UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Need Help With C# Sqldataadapter    
 
   
gunderj
post Sep 16 2013, 09:09 AM
Post#1



Posts: 194
Joined: 5-September 05



I am using SqlDataAdapter to populate my DataSet from a query via a SQL Server stored procedure. After a full day of debugging the null object error, I hope someone here can advise me. First I will paste the c# code, then the stored proceduure and third I paste the error.
Thanks so much if someone can spot the problem.
#:
DataSet ds3 = new DataSet("myTable");
try
{
conn.Open();
SqlDataAdapter da3 = new SqlDataAdapter();
System.Data.SqlClient.SqlCommand SQL = new SqlCommand("[dbo].[sp_test]", conn);
da3.SelectCommand = SQL;
SQL.CommandType = CommandType.StoredProcedure;
SQL.Parameters.AddWithValue("@ibtNumber", ibtNumber_requested);
da3.Fill(ds3,"myTable"); // this is causing the error!!
conn.Close();
}
catch (Exception ex)
{
throw ex;
}
stored procedure:
ALTER PROCEDURE [dbo].[sp_test]
(
@ibtNumber nvarchar(8)
)
AS
begin
select *
from myTable a
where a.ibtNumber = @ibtNumber
end
error:
Exception caught: System.NullReferenceException: Object reference not set to an instance of an object.
With debug I have proved the da3.fill statement is causing the error.
Thanks,
Jay
Go to the top of the page
 
Kamulegeya
post Sep 16 2013, 11:26 AM
Post#2



Posts: 1,767
Joined: 5-September 10
From: Kampala,Uganda The Pearl of Africa


Hello
ere
CODE
DataSet ds3 = new DataSet("myTable");

and
CODE
da3.Fill(ds3,"myTable");  // this is causing the error!!

I think it might be conflicting
Try for the first line
CODE
DataSet ds3 = new DataSet();

for the second line
CODE
DataTable myTable=New DataTable();
da3.Fill(ds3,"myTable")

Ronald
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    11th December 2017 - 06:11 AM