Вот мой код - мне просто нужно преобразовать SQL DataSet в DataTable в asp.net 4.5. Кажется, я не понимаю. Есть много сообщений, делающих обратное, но ничто из того, что я не могу найти, это четко отвечает.Как преобразовать DataSet в DataTable в C#
public static DataTable getGender()
{
DataTable DT = default(DataTable);
SqlConnection con = new SqlConnection(CnnString.ConnectionString.ToString());
SqlCommand cmd = new SqlCommand("ns_gender_get", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
try
{
//Fill the Dataset
da.Fill(ds, "Results");
DT = ds.Tables(0);
//**GOAL: I need to assign the DS.Table(0) to the DT (dataTable) so when this method is called it will return the table rows in the DT.
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
con = null;
}
return DT;
}
Вы пробовали просто вернув таблицу? Вместо DT = ds.Tables [0]; использовать return ds.Tables [0]; – Kevin
Спасибо ... Я наконец нашел его (сразу после публикации этого!) Ds.Tables.Add (DT); –