Thursday, March 22, 2012

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

can someone please shed some light in this please

rgs

Tony

Server Error in '/' 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:


<%@dotnet.itags.org. Page Language="VB" %>
<%@dotnet.itags.org. import Namespace="System.Data" %>
<%@dotnet.itags.org. import Namespace="System.Data.sqlclient" %>
<%@dotnet.itags.org. import Namespace="System.Web.Mail" %
<script runat="server"
Dim dataSet As System.Data.DataSet

Sub Button1_Click(sender As Object, e As EventArgs)
'dim dataseta as new dataset
dim pw as string = "apple21"

call MyQueryMethod(pw)
'
If dataset.Tables(0).rows.count <> 0 then response.write("hello")

'response.write(dataset.tables(0).rows(0).item(0))

End Sub
Function MyQueryMethod(ByVal password As String) As System.Data.DataSet
Dim connectionString As String = "server=xxxxx.87.xxx.xxx; user id=xxxx.150'; password=xxxxxx; database=xxxxx"& _
"xxxx.150'"
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)

Dim queryString As String = "SELECT [tblReg].[UserName], [tblReg].[Password] FROM [tblReg] WHERE ([tblReg].[Pa"& _
"ssword] = @dotnet.itags.org.Password)"
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_password As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_password.ParameterName = "@dotnet.itags.org.Password"
dbParam_password.Value = password
dbParam_password.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_password)

Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)

'Return dataSet
End Function

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button>
<!-- Insert content here -->
</form>
</body>
</html

Might be this line:


If dataset.Tables(0).rows.count <> 0 then response.write("hello")

If the dataset or dataset table is nothing then you cannot get the count...might check that the dataset & table exists first, before trying to get the count.

Anyway, looks like your dataset will never get filled with this code as your Return Dataset line is commented out in the function MyQueryMethod...

MajorCats

0 comments:

Post a Comment