public static DataTable GetDataTable(string sqlStr)
{
SqlConnection conn = new SqlConnection(str);//读取数据库字符串
if (conn.State == ConnectionState.Closed)//如果现在数据库的状态是关闭,则打开数据库
{
conn.Open();
}
SqlCommand cmd = new SqlCommand(sqlStr,conn);(1)
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
conn.Close();
return dt;
}
苦逼的代码狗
相关分类