Problem in the Execution of server Script - ASP.NET

E

ElanKathir

I am faceing problem in the Execution of server Script. Error and Code pasted here..
Please help me !

Thanks & Regards,
Elankathir.
---------------------------------------Code------------------------------------------------------------



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim objDataSet As New DataSet()

Dim x As DataRow

Dim dt As New DataTable()

Dim dr As DataRow

' For Dynamic Dataset without Database

dt.Columns.Add("txt1", Type.GetType("System.String"))

dt.Columns.Add("txt2", Type.GetType("System.String"))

dr = dt.NewRow

dr("txt1") = "Kathir"

dr("txt2") = "Elan"

dt.Rows.Add(dr)

objDataSet.Tables.Add(dt)



DataGrid1.DataSource = objDataSet

DataGrid1.DataBind()

End Sub

----------------------------------------Error-----------------------------------------------------------
Server Error in '/Elan_Sample' Application.

--------------------------------------------------------------------------------

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 43: dt.Rows.Add(dr)
Line 44: objDataSet.Tables.Add(dt)
Line 45: DataGrid1.DataSource = objDataSet
Line 46: DataGrid1.DataBind()
Line 47: For Each x In objDataSet.Tables(0).Rows


Source File: C:\Project Files\Root\Elan_Sample\WebForm1.aspx.vb Line: 45
 
A

Andrea D'Onofrio [MSFT]

Hi,
your code should works fine.
Let me know the line of code that declares the DataGrid1 object and the environment details.

Have you tried to drag & drop a new DataGRid control and use your code with this one?

HtH,
Andrea
 
E

ElanKathir .S.N

I got the Point, Yes Grid was not there....
Thanks for your reply.

and What is this ?
--
This posting is provided "AS IS" with no warranties, and confers no
rights.


Thanks & Regards

Elankathir,
B'lore,
India.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top