hello friends
this is my code to get data from database table.
try
{
Dob.open();
SqlCommand cmd6 = new SqlCommand("sp_combo1", Dob.con);
cmd6.CommandType = CommandType.StoredProcedure;
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd6;
DataSet ds = new DataSet();
sda.Fill(ds);
DataTable dt = ds.Tables["Acadamic_year"];
return dt;
What is the error in this code.dateset does not getting table from database.
Loading

Hemant KumarRank #1,202 · 1.5K reputationPosted Jul 27, 2012, 5:05 AM EDT
try
{
Dob.open();
SqlCommand cmd6 = new SqlCommand("sp_combo1", Dob.con);
cmd6.CommandType = CommandType.StoredProcedure;
SqlDataAdapter sda = new SqlDataAdapter(cmd6,Dob);
DataSet ds = new DataSet();
sda.Fill(ds);
DataTable dt = ds.Tables["Acadamic_year"];
return dt;
Santhosh Kumar JayaramanRank #563 · 4.3K reputationPosted Jul 27, 2012, 5:16 AM EDT
whats your connection ??
you said Dob.Open()
and in the command you said Dob.con
baskaran chellasamy112 reputationPosted Jul 27, 2012, 7:17 AM EDT
Hemant KumarRank #1,202 · 1.5K reputationPosted Jul 29, 2012, 9:48 PM EDT
You have to pass the Parameter as given below
try
{
Dob.open();
SqlCommand cmd6 = new SqlCommand("sp_combo1", Dob.con);
cmd6.CommandType = CommandType.StoredProcedure;
SqlDataAdapter sda = new SqlDataAdapter(cmd6,Dob);
cmd6.Parameter.AddWithValue("@InDate",DateTime.Now);
DataSet ds = new DataSet();
sda.Fill(ds);
DataTable dt = ds.Tables["Acadamic_year"];
return dt;
}
catch(Exception ex)
{
}
refer this link
http://stackoverflow.com/questions/3806229/how-to-pass-value-to-a-stored-procedure-using-c-sharp