Here is my code:
I have a textbox for the email address, and a Label to get the sellerID from the seller Table
And the Submit button I have this code:
GetSellerID(txtemail.Text)
datarad = ds.Tables(0).Rows(0)
lblsellerID.Text = datarad.Item(0)
Note: I have created a function name GetSellerID I also have a store Procedure call SellerID. I have tested this it works fine using query analyzer.
This is function:
Public Function GetSellerID(ByVal Email As String) As DataSet
sql = "exec SellerID " & "Email"
Dim connString As String = "Server=localhost; Initial Catalog=mydatabase; UID=sa; Password=mypwd; Network Library=dbmssocn;"
Dim conn As SqlConnection = New SqlConnection(connString)
'Dim command As SqlCommand = New SqlCommand(sql, conn)
Dim da As SqlDataAdapter = New SqlDataAdapter(sql, conn)
Dim ds As DataSet = New DataSet
conn.Open()
Try
'
da.Fill(ds, "Seller")
Return ds
Catch e As SqlException
Throw (e)
Finally
conn.Close()
End Try
End Function
when I click the submit I get this error :Object reference not set to an instance of an object.
Please Help.
Thanks in adavance. I am using visual studio 2003.what is the offending line of code according to the 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 99:
Line 100: GetSellerID(txtemail.Text)
Line 101: datarad = ds.Tables(0).Rows(0)
Line 102: lblsellerID.Text = datarad.Item(0)
Line 103:
Source File: d:\inetpub\wwwroot\Computers\Seller.aspx.vb Line: 101
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Computers.Seller.btnsend_Click(Object sender, EventArgs e) in d:\inetpub\wwwroot\Computers\Seller.aspx.vb:101
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
if i am reading this correctly, GEtSellarID is a function which returns a dataset containing your data.
looking at your code you call GetSellerID and dont catch the dataset return value
in your code .make it the following
dim _ds as dataset = getsellerid(txtemail.text)
_ds.tables(0).rows(0) will now contain your data.
Hi Richy
thanks for the reply. I tried the code:
Dim ds As DataSet = GetSellerID(txtemail.Text)
datarad = ds.Tables(0).Rows(0)
lblsellerID.Text = datarad.Item(0)
When I run the application it states
There is no row at position 0.
Sorry:
I found that was a bit of error in my GetSeller function. it is working fine fine
Thanks a lot for the help
0 comments:
Post a Comment