Using SqlDataAdapter to fill DataTable in c#
public DataTable List(string sql)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[“DefaultConnection”].ConnectionString);
SqlCommand cmd = new SqlCommand(sql, con);
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[“DefaultConnection”].ConnectionString);
SqlCommand cmd = new SqlCommand(sql, con);
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
try
{
con.Open();
da.Fill(dt);
}
finally
{
con.Close();
}
return dt;
}