wpf对数据库简单操作

class SqlFrom
{
public static SqlConnection con;
public static void ConnSql() {
//每次使用时都要打开数据库
con = new SqlConnection();
con.ConnectionString = "server=.;database=TestDb;uid=sa;pwd=sql";
con.Open();
}
public static int AddData(string sql) {
SqlCommand cmd = con.CreateCommand();
//cmd.CommandText = "insert into Student values('000','000','000','000','')";
cmd.CommandText = sql;
int count= cmd.ExecuteNonQuery();
if (count > 0)
{
return 1; //表示成功
}
else
{
return 0; //表示失败
}
con.Close(); //结束时都要关闭
}
}

猜你喜欢

转载自www.cnblogs.com/ganzhihui/p/10457577.html
今日推荐