Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
DataSet11.Tables("Patient").Rows(DataGridView1.CurrentRow.Index).Delete()
sqlDataAdapter1.Update(DataSet11, "Patient") '此行报错,提示当传递具有已删除行的 DataRow 集合时,Update 要求有效的 DeleteCommand
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
PictureBox1.Image = Nothing
End Sub
我这段代码可以实现吗?这个错误我已经改了好久了,都解决不了,只有来麻烦大家了
12 个解决方案
#1
...
dim cb as System.Data.SqlClient.SqlCommandBuilder = new System.Data.SqlClient.SqlCommandBuilder(sqlDataAdapter1) '加上这句代码
sqlDataAdapter1.Update(DataSet11, "Patient")
...
#2
恩,但是现在提示DataAdapter.SelectCommand 属性需要初始化这个错误的
#3
我也在找.天啊,这个很难吗?
#4
DataAdapter1你fill dataset时没有初始化Selectcommand吗?
#5
没的,这个要怎么初始化的啊?
#6
可以触发datagridview的keydown事件,来判断是否按下delete键,如果是则传select row里的数据到删除的存储过程,然后再重新读取存储过程就可以了
#7
'加上这句代码
dim cb as System.Data.SqlClient.SqlCommandBuilder = new System.Data.SqlClient.SqlCommandBuilder(sqlDataAdapter1) sqlDataAdapter1.SelectCommand=new SqlCommand("SELECT * FROM Patient",sqlConnection1)sqlDataAdapter1.Update(DataSet11, "Patient")
#8
咋还不换行了?
'加上这句代码
dim cb as System.Data.SqlClient.SqlCommandBuilder = new System.Data.SqlClient.SqlCommandBuilder(sqlDataAdapter1)
sqlDataAdapter1.SelectCommand=new SqlCommand("SELECT * FROM Patient",sqlConnection1)
sqlDataAdapter1.Update(DataSet11, "Patient")
#9
调下顺序
sqlDataAdapter1.SelectCommand=new SqlCommand("SELECT * FROM Patient",sqlConnection1)
'加上这句代码
dim cb as System.Data.SqlClient.SqlCommandBuilder = new System.Data.SqlClient.SqlCommandBuilder(sqlDataAdapter1)
sqlDataAdapter1.Update(DataSet11, "Patient")
#10
还是一样的错误提示的
#11
sqlDataAdapter1在初始化时要有如下语句:SELECT * FROM Patient
已经建立了:SqlCommandBuilder
且:Patient表中要有主鍵
已经建立了:SqlCommandBuilder
且:Patient表中要有主鍵
#12
恩,有主键的,是id,第二条是什么啊
#1
...
dim cb as System.Data.SqlClient.SqlCommandBuilder = new System.Data.SqlClient.SqlCommandBuilder(sqlDataAdapter1) '加上这句代码
sqlDataAdapter1.Update(DataSet11, "Patient")
...
#2
恩,但是现在提示DataAdapter.SelectCommand 属性需要初始化这个错误的
#3
我也在找.天啊,这个很难吗?
#4
DataAdapter1你fill dataset时没有初始化Selectcommand吗?
#5
没的,这个要怎么初始化的啊?
#6
可以触发datagridview的keydown事件,来判断是否按下delete键,如果是则传select row里的数据到删除的存储过程,然后再重新读取存储过程就可以了
#7
'加上这句代码
dim cb as System.Data.SqlClient.SqlCommandBuilder = new System.Data.SqlClient.SqlCommandBuilder(sqlDataAdapter1) sqlDataAdapter1.SelectCommand=new SqlCommand("SELECT * FROM Patient",sqlConnection1)sqlDataAdapter1.Update(DataSet11, "Patient")
#8
咋还不换行了?
'加上这句代码
dim cb as System.Data.SqlClient.SqlCommandBuilder = new System.Data.SqlClient.SqlCommandBuilder(sqlDataAdapter1)
sqlDataAdapter1.SelectCommand=new SqlCommand("SELECT * FROM Patient",sqlConnection1)
sqlDataAdapter1.Update(DataSet11, "Patient")
#9
调下顺序
sqlDataAdapter1.SelectCommand=new SqlCommand("SELECT * FROM Patient",sqlConnection1)
'加上这句代码
dim cb as System.Data.SqlClient.SqlCommandBuilder = new System.Data.SqlClient.SqlCommandBuilder(sqlDataAdapter1)
sqlDataAdapter1.Update(DataSet11, "Patient")
#10
还是一样的错误提示的
#11
sqlDataAdapter1在初始化时要有如下语句:SELECT * FROM Patient
已经建立了:SqlCommandBuilder
且:Patient表中要有主鍵
已经建立了:SqlCommandBuilder
且:Patient表中要有主鍵
#12
恩,有主键的,是id,第二条是什么啊