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 12: Dim profile As DataSet
Line 13: Profile = get_profile(UID)
Line 14: TB_FName.Text = profile.Tables.Item("uprofile").Rows.Item(0).Item("fname").ToString
Source File: c:\inetpub\wwwroot\createuser.aspx.vb Line: 14
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
createuser_aspx.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\createuser.aspx.vb:14
System.Web.UI.Control.OnLoad(EventArgs e) +102
System.Web.UI.Control.LoadRecursive() +45
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +952
aspx file imports the class profile
I am using a function get_profile
Imports Microsoft.VisualBasic
Imports system.data
Imports system.data.Odbc
Public class profile
public shared function get_profile (ByVal uid as Integer) as DataSet
Dim myConn As OdbcConnection = New OdbcConnection("connectionstring")
myConn.Open()
Dim SQL As String
SQL = "SELECT * from uprofile WHERE uid=" & uid
Dim DS_Profile As New DataSet
Dim DA_Profile As New OdbcDataAdapter
DA_Profile.SelectCommand = New OdbcCommand(SQL, myConn)
DA_Profile.Fill(DS_Profile)
Return DS_Profile
End Function
I assume that the profile variable will pick up the dataset as a return value
I do not really understand why the error is coming.
Thanks for the helpMake sure the Select statement really return a value based on the uid. If you are 100% sure that the select statement returns rows, make sure the "fname" field is not a DBNull.
0 comments:
Post a Comment