command.CommandText = insertstr; connection.Open(); command.ExecuteNonQuery(); MessageBox.Show(\学生添加成功!\提示\MessageBoxIcon.Information); connection.Close(); } 方法二: 复制代码代码如下: string str = \string insertstr = \SqlDataAdapter sda = new SqlDataAdapter(str, connection); DataSet ds = new DataSet(); sda.Fill(ds, \DataTable dt = ds.Tables[\DataRow dr = dt.NewRow(); dr[\dr[\dt.Rows.Add(dr); sda.InsertCommand = new SqlCommand(insertstr, connection); sda.Update(ds, \MessageBox.Show(\学生添加成功!\提示\MessageBoxIcon.Information); (3)修改数据库中的数据 方法一: 复制代码代码如下: string snum = tBstudentnum.Text.Trim(); string sname = tBstudentname.Text.Trim(); if (snum == \{ MessageBox.Show(\学生学号或姓名不能为空!\错误\MessageBoxIcon.Error); } else { string modifystr = \\command.CommandText = modifystr; connection.Open(); command.ExecuteNonQuery(); MessageBox.Show(\学生的姓名修改成功!\提示\MessageBoxIcon.Information ); connection.Close(); 方法二: 复制代码代码如下: string snum = tBstudentnum.Text.Trim(); string sname = tBstudentname.Text.Trim(); if (snum == \{ MessageBox.Show(\学生学号或姓名不能为空!\错误\MessageBoxIcon.Error); } else { string str = \string updatestr = \\SqlDataAdapter sda = new SqlDataAdapter(str, connection); DataSet ds = new DataSet(); sda.Fill(ds, \DataTable dt = ds.Tables[\dt.Rows[0][\sda.UpdateCommand = new SqlCommand(updatestr , connection); sda.Update(ds, \MessageBox.Show(\学生姓名修改成功!\提示\MessageBoxIcon.Information); } (4)删除数据库中的数据 方法一: 复制代码代码如下: string snum = tBstudentnum.Text.Trim(); if (snum == \{ MessageBox.Show(\学生学号不能为空!\错误\MessageBoxIcon.Error); } else { string str = \string deletestr = \command.CommandText =str ; connection.Open(); if (command.ExecuteScalar() == null) { MessageBox.Show(\此学号对应的学生不存在!\错误\MessageBoxIcon.Error); } else { command.CommandText = deletestr; command.ExecuteNonQuery(); MessageBox.Show(\学生的信息删除成功!\提示\MessageBoxIcon.Information); } connection.Close(); 方二: 复制代码代码如下: string str = \string deletestr = \SqlDataAdapter sda = new SqlDataAdapter(str, connection); DataSet ds = new DataSet(); sda.Fill(ds, \DataTable dt = ds.Tables[\if (dt.Rows.Count > 0) { dt.Rows[0].Delete(); sda.DeleteCommand = new SqlCommand(deletestr, connection); sda.Update(ds, \MessageBox.Show(\学生信息删除成功!\提示\MessageBoxIcon.Information); } else { MessageBox.Show(\此学号对应的学生不存在!\错误\MessageBoxIcon.Error); }
vs+sql(2)
2018-12-29 22:34
vs+sql(2).doc
将本文的Word文档下载到电脑
下载失败或者文档不完整,请联系客服人员解决!