Search code examples
sqldataadapter

Why does my SQL dataset always return a count of 0?


I'm trying to fill a Dataset. It worked when I did it by direct query but have moved to a stored procedure. The stored procedure does work and returns the rows desired with the desired userID/Password.

var connectionString = ConfigurationManager.ConnectionStrings["InformConnectionString"].ConnectionString;
var MyConnection = new SqlConnection(connectionString);
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand();
cmd.Connection = MyConnection;
cmd.CommandText = "sp_genDSPdata";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@startdate", SqlDbType.DateTime).Value = Convert.ToDateTime(startString);
cmd.Parameters.Add("@enddate", SqlDbType.DateTime).Value = Convert.ToDateTime(endString);
SqlDataAdapter adap = new SqlDataAdapter(cmd);
adap.Fill(ds);
return ds;

ds has a count of 0. When I execute the sp, it returns about 2500 rows. I have tried many things and this is my latest attempt. Does anyone see anything obviously wrong? No errors. Just empty ds. I had an error in the fill when I tried to pass strings because it was an incorrect sqldatatype. This tells me that it tried to execute the sp. So, I converted the strings to datetime and it went to the next line but the ds is empty. Hope this is enough info.


Solution

  • Well, for those of you that might seem interested, I was not naming my table. This prevented my program from reading the information from the correct place. Consequently, null was all I ever got. I knew it had to be something basic. Thank you for your interest.