Thursday, March 8, 2012

call to stored proc returning null datatable

I have a stored proc which should be returning a datatable. When I execute it manually it returns all requested results. However, when I call it via code (C#) it is returning a null table which leads me to believe the problem is in my code. I'm not getting any errors during runtime. Any help at all would be a BIG help!

private void PopulateControls()
{
DataTable table = CartAccess.getCart();
}

public static DataTable getCart()
{
DbCommand comm = GenericDataAccess.CreateCommand();
comm.CommandText = "sp_cartGetCart";

DbParameter param = comm.CreateParameter();
param.ParameterName = "@.CartID";
param.Value = cartID;
param.DbType = DbType.String;
param.Size = 36;
comm.Parameters.Add(param);

DataTable table = (GenericDataAccess.ExecuteSelectCommand(comm));
return table;
}


public static DataTable ExecuteSelectCommand(DbCommand command)
{
// The DataTable to be returned
DataTable table;
// Execute the command making sure the connection gets closed in the end
try
{
// Open the data connection
command.Connection.Open();
// Execute the command and save the results in a DataTable
DbDataReader reader = command.ExecuteReader();
table = new DataTable();
table.Load(reader);
// Close the reader
reader.Close();
}
catch (Exception ex)
{
Utilities.SendErrorLogEmail(ex);
throw ex;
}
finally
{
// Close the connection
command.Connection.Close();
}
return table;
}

Nevermind I figured it out.

No comments:

Post a Comment