一、查
SqlConnection conn = new SqlConnection();
conn.ConnectionString = sqlb.ConnectionString;
conn.Open();
string sqlstr="";
SqlDataAdapter adap = new SqlDataAdapter(sqlstr, conn);
DataSet ds = new DataSet();
adap.Fill(ds);
DataTable dt = ds.Tables[0];
if(dt.Rows.Count==1)
{
MainForm2 mf = new MainForm2();
mf.Show();
this.Hide();
}
二、 删除
string sqlstr = "delete from d_user where realname='" + username + "'";
SqlCommand scd = new SqlCommand(sqlstr, conn);
int n = scd.ExecuteNonQuery();
if (n > 0)
{
MessageBox.Show("删除成功!");
}
三、插入增加
string sqlstr = "insert into d_user (username,dep,realname,cpnum,password,major) values (" + "'" + t_logname + "'," + "'" + t_dep + "'," + "'" + t_name + "','"+t_cpnum+"','"+"123','"+t_major+"')";
SqlCommand sqlcmd = new SqlCommand(sqlstr, conn);
n = sqlcmd.ExecuteNonQuery();
if (n > 0)
{
MessageBox.Show("保存成功");
}
else
{
MessageBox.Show("保存失败");
}
四、修改
string SQLstr = "update cslist set bzdm='" + bzdmstr + "',cs_content='" + bznrstr + "',bzfl='"+bzflstr+"',locationx='"+rowstr+"',locationy='"+colstr+"' where bzdm='"+bzdm+"'";
// MessageBox.Show(SQLstr);
SqlCommand sqlcmd = new SqlCommand(SQLstr, conn);
int n;
n = sqlcmd.ExecuteNonQuery();
if (n > 0)
{
MessageBox.Show("修改成功");
}