Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Problems calling stored procedures


Message #1 by "Hugh McLaughlin" <hugh@k...> on Sat, 12 Jan 2002 17:01:14
Hello Everyone and thanks for your help in advance.  I am just getting my 

feet wet calling stored procedures from ASP.Net pages and am encountering 

a problem that I can't solve.  Here is the code I am using:



<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.SqlClient" %>





<%

      		Dim myConnection As SQLConnection

      		Dim myCommand As SQLCommand

      		Dim ConnStr   As String 

= "server=myserver;uid=sa;pwd=;database=MyDatabase"



      		myConnection = New SQLConnection(ConnStr)

      		myConnection.Open()



            	' Mark the Command as a SPROC

            	myCommand.Connection = myConnection

            	myCommand.CommandType = CommandType.StoredProcedure

            	myCommand.CommandText = "[sp_ReadUsers]"



		myDatagrid.DataSource=myCommand.ExecuteReader

(CommandBehavior.CloseConnection)



		Page.Databind()



		

%>

 <ASP:DataGrid id="MyDataGrid" runat="server" />



I am receiving the following error message:



"Value null was found where an instance of an object was required."



I have verified that the sp_ReadUsers stored procedure works as it returns 

the appropriate recordset when it is run in Query Analyzer.  I have also 

verified that there are no NULL records or data fields.



Any help with this problem would be greatly appreciated.  Thanks.



Message #2 by "Albert Davis" <albertdavis@h...> on Sat, 12 Jan 2002 12:21:39 -0500
You haven't instanciated myCommand yet (e.g. myCommand = new SQLCommand)...





>From: "Hugh McLaughlin" <hugh@k...>

>Reply-To: "ASP+" <aspx@p...>

>To: "ASP+" <aspx@p...>

>Subject: [aspx] Problems calling stored procedures

>Date: Sat, 12 Jan 2002 17:01:14

>

>Hello Everyone and thanks for your help in advance.  I am just getting my

>feet wet calling stored procedures from ASP.Net pages and am encountering

>a problem that I can't solve.  Here is the code I am using:

>

><%@ Import Namespace="System.Data" %>

><%@ Import Namespace="System.Data.SqlClient" %>

>

>

><%

>       		Dim myConnection As SQLConnection

>       		Dim myCommand As SQLCommand

>       		Dim ConnStr   As String

>= "server=myserver;uid=sa;pwd=;database=MyDatabase"

>

>       		myConnection = New SQLConnection(ConnStr)

>       		myConnection.Open()

>

>             	' Mark the Command as a SPROC

>             	myCommand.Connection = myConnection

>             	myCommand.CommandType = CommandType.StoredProcedure

>             	myCommand.CommandText = "[sp_ReadUsers]"

>

>		myDatagrid.DataSource=myCommand.ExecuteReader

>(CommandBehavior.CloseConnection)

>

>		Page.Databind()

>

>

>%>

>  <ASP:DataGrid id="MyDataGrid" runat="server" />

>

>I am receiving the following error message:

>

>"Value null was found where an instance of an object was required."

>

>I have verified that the sp_ReadUsers stored procedure works as it returns

>the appropriate recordset when it is run in Query Analyzer.  I have also

>verified that there are no NULL records or data fields.

>

>Any help with this problem would be greatly appreciated.  Thanks.

>

>












_________________________________________________________________

Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.




  Return to Index