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 KumarPosted Jul 30, 2012, 1:48 AM
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
baskaran chellasamyPosted Jul 27, 2012, 11:17 AM
Santhosh Kumar JayaramanPosted Jul 27, 2012, 9:16 AM
whats your connection ??
you said Dob.Open()
and in the command you said Dob.con
Hemant KumarPosted Jul 27, 2012, 9:05 AM
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;