我的代码如下
GRADE表的主键为stunum和coursename,我要删除学号为textBox.text的信息
string findgradestu = "Select * From GRADE where stunum='" + textBox1.Text +"'";//要删除的信息
DataSet ds1 = new DataSet();
SqlDataAdapter sda1 = new SqlDataAdapter(findgradestu, thisConnection);
SqlCommandBuilder scb1 = new SqlCommandBuilder(sda1);
sda1.Fill(ds1, "GRADE");
DataColumn[] keys= new DataColumn[2];
keys[0] = ds1.Tables["GRADE"].Columns["stunum"];
keys[1] = ds1.Tables["GRADE"].Columns["coursename"];
ds1.Tables["GRADE"].PrimaryKey = keys;
DataRow findRow1 = ds1.Tables["GRADE"].Rows.Find(textBox1 .Text );//但是这句话会报错啊,很纠结
if (findRow1 == null)
{
MessageBox.Show("null");
}
else
{
findRow1.Delete();
sda1.Update(ds1, "GRADE");
}
请各位大侠帮我改下代码吧。
GRADE表的主键为stunum和coursename,我要删除学号为textBox.text的信息
string findgradestu = "Select * From GRADE where stunum='" + textBox1.Text +"'";//要删除的信息
DataSet ds1 = new DataSet();
SqlDataAdapter sda1 = new SqlDataAdapter(findgradestu, thisConnection);
SqlCommandBuilder scb1 = new SqlCommandBuilder(sda1);
sda1.Fill(ds1, "GRADE");
DataColumn[] keys= new DataColumn[2];
keys[0] = ds1.Tables["GRADE"].Columns["stunum"];
keys[1] = ds1.Tables["GRADE"].Columns["coursename"];
ds1.Tables["GRADE"].PrimaryKey = keys;
DataRow findRow1 = ds1.Tables["GRADE"].Rows.Find(textBox1 .Text );//但是这句话会报错啊,很纠结
if (findRow1 == null)
{
MessageBox.Show("null");
}
else
{
findRow1.Delete();
sda1.Update(ds1, "GRADE");
}
请各位大侠帮我改下代码吧。
解决方案 »
- 请问想做一个基于B/S架构的人事系统,需要用到一些什么语言或技术?
- 能不能在services里面启动两个线程
- asp.net 对excel操作
- MyFile.Seek(-1, SeekOrigin.Current) 这句是什么意思?
- treeview新增节点后触发什么事件?
- 怎么设置树节点不可见
- 怎么把 arraylist里的内容赋给一个textbox
- 项目发布后,xp安装弹出GAC System.Data.Entity 版本 3.5.0
- !!!请教字符串比对!!!!
- C#中有类似Vb的strconv函数可以转换简体繁体(中文)吗?求助-----
- 想重载button控件 怎么才能知道接口呢
- C# 如何调用Excel的柱状图?
不是字符串
object[]findTheseVals = new object[3];
findTheseVals[0] = "";
findTheseVals[1] = "";
foundRow = myTable.Rows.Find(findTheseVals);