Copy store procedure result to dataset or datatable
I have store procedure which has select query..How to copy to datatable using linq ?.?
Var a= from r in DC.storeprocedure select r;
Datatable DT= ?????
DataTable table = new DataTable();
using(var con = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString))
using(var cmd = new SqlCommand("usp_GetABCD", con))
using(var da = new SqlDataAdapter(cmd))
{
cmd.CommandType = CommandType.StoredProcedure;
da.Fill(table);
}
Datatable DT = new DataTable();
DataAdapater DA = new Data Adapter();
DA.SelectCommand = new SqlCommand(sql, conn); // Query and Connection
DA.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet DS = new DataSet();
DA.Fill(DS,"Any_NAME") // You got your Dataset Filled
//Data Table
DataTable DT = DS.Tables["Table1"]// Any table in the dataset
using (SqlConnection Con = new SqlConnection(sqlCon))
{
SqlCommand Com = new SqlCommand();
Con.Open();
Com.CommandText = "SP_Name";
Com.CommandType = CommandType.StoredProcedure;
Com.Connection = Con;
SqlParameter pQuery = new SqlParameter();
//Setting the properties of Sql parameter
pQuery.SqlDbType = SqlDbType.VarChar;
pQuery.Direction = ParameterDirection.Input;
pQuery.Size = 8000;
pQuery.ParameterName = "@strQuery";
pQuery.Value = DBNull.Value;
Com.Parameters.Add(pQuery);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = Com;
da.Fill(datasetName);
}
}