Hi friends,
I want to write a method to return a DataTable Object.. Input parameters can be overloaded depending on parameters required by Stored Procedure..
How can i write this please guide as i am new to c#
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Santhosh Kumar JayaramanPosted Jul 19, 2012, 1:11 AM
params SqlParameter[] arrParam)
{
DataTable dt = new DataTable();
using (SqlConnection cnn = new SqlConnection(
"Data Source=.\sqlexpress;Initial Catalog=NorthWind;
Integrated Security=True"))
{
cnn.Open();
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = cnn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = storedProcedureName;
if (arrParam != null)
{
foreach (SqlParameter param in arrParam)
cmd.Parameters.Add(param);
}
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);
}
}
}
return dt;
}
rani m mkPosted Jul 19, 2012, 3:16 AM