Wednesday, March 21, 2012

help -Object reference not set to an instance of an object.

i m new for asp.net

when i run app. i got this error,

-----
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 49:
Line 50: adpt.Fill(ds, "SMS_student_class_master")
Line 51: txt.Text = ds.Tables.Item("roll_no").ToString
Line 52: con.Close()
Line 53: End Sub

Source File: c:\inetpub\wwwroot\aspnet\sms\assignment_d.aspx.vb Line: 51
------

my source code given below,

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsNothing(Request.QueryString("id")) Then
sid = Request.QueryString("id")
End If
Dim con As New SqlConnection
Dim constr As String
Dim cmd As New SqlCommand
Dim ds As New DataSet
Dim adpt As New SqlDataAdapter

constr = "data source=Baroda;user id=sa;password=;" & _
"initial catalog=SMS;persist security info=False;workstation id=Baroda;Packet size=4096"
con.ConnectionString = constr
con.Open()

cmd.CommandText = "SELECT * FROM SMS_student_class_master WHERE " & _
"stud_id='" + sid + "'"
cmd.Connection = con
adpt.SelectCommand = cmd

adpt.Fill(ds, "SMS_student_class_master")
txt.Text = ds.Tables.Item("roll_no").ToString
con.Close()
End Sub
---

what should i do?
anyone have any idea?
plz give solution.
its urgent.

thanks in advance.cmd.Connection = con
adpt = new SqlDataAdapter(cmd)
adpt.Fill(...)

No comments:

Post a Comment