rik,
Did you create a new SqlCommand for your data adapter's SelectCommand?
// Create the SelectCommand.
cmd = new SqlCommand("SELECT * FROM Customers " +
"WHERE Country = @Country AND City = @City", conn);
cmd.Parameters.Add("@Country", SqlDbType.NVarChar, 15);
cmd.Parameters.Add("@City", SqlDbType.NVarChar, 15);
da.SelectCommand = cmd;
Lars
>im getting the dreaded:
>Object reference not set to an instance of an object.
[quoted text clipped - 24 lines]
>Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
>Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
rbutch@coair.com - 31 May 2005 20:35 GMT
yes i did.
and the command type was a stored procedure.
da.SelectCommand.CommandType = CommandType.StoredProcedure;
thanks
rik
larzeb - 31 May 2005 21:35 GMT
rik,
Where are you assigning the newly created SqlCommand to the new SqlDataAdapter? Something like:
da.SelectCommand = cmd;
>yes i did.
>and the command type was a stored procedure.
[quoted text clipped - 7 lines]
>Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
>Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
rbutch@coair.com - 31 May 2005 21:59 GMT
i thought what i sent you was that.
i basically ripped this right off of the microsoft website:
http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3BQ320916
rbutch@coair.com - 01 Jun 2005 00:29 GMT
i figured this one out. there are so many ways of doing things in .net both right and wrong. but, this one works just fine.
many many thanks for your help
rik
SqlConnection myConnection = new SqlConnection("Data Source=(Local);Initial Catalog=A39;Integrated Security=SSPI");
SqlCommand command = new SqlCommand("GetAuditTimeCard",myConnection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@PERIOD", SqlDbType.DateTime).Value = txtPpe.Text;
SqlDataAdapter da = new SqlDataAdapter(command);
DataSet ds = new DataSet();
myConnection.Open();
da.Fill(ds,"TimeCard");
Dg1.DataSource = ds.Tables["TimeCard"].DefaultView;
Dg1.DataBind();
myConnection.Close();
da.Dispose();