Call SELECT Stored Procedure in c#.net
Main
String strStoreProcName = "Store Procedure Name";
SqlCommand cmd = new SqlCommand(strStoreProcName);
//Add number of Paramaters
cmd.Parameters.AddWithValue("@Parameter Name in datebase", Parameter value);
datatable = GetData(cmd);
Function
public DataTable GetData(SqlCommand cmd)
{
DataTable dt = new DataTable();
String strConnString= System.Configuration.ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
cmd.Connection = con ;
SqlDataAdapter sda = new SqlDataAdapter();
cmd.CommandType = CommandType.StoredProcedure;
try
{
con.Open();
sda.SelectCommand = cmd;
sda.Fill(dt);
}
catch (Exception ex)
{
return dt;
}
finally
{
con.Close();
cmd.Dispose();
sda.Dispose();
}
return dt;
}
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home