导入命名空间
using System.Data;
using System.Data.SqlClient;
public static DataSet GetDataSet(string sql)
{
string str = "Data Source=.;Initial Catalog=Students;Integrated Security=True";
SqlConnection conn = new SqlConnection(str);
try
{
conn.Open();
DataSet set = new DataSet();
SqlDataAdapter adapter=new SqlDataAdapter (sql,conn);
adapter.Fill(set);
conn.Close();
return set;
}
catch (Exception)
{
throw;
}
}
public static int GetExecuteNonQuery(string sql)
{
string str = "Data Source=.;Initial Catalog=Students;Integrated Security=True";
SqlConnection conn = new SqlConnection(str);
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
int res = cmd.ExecuteNonQuery();
conn.Close();
return res;
}
catch (Exception)
{
throw;
}
}