未将对象引用设置到对象的实例。哪里的问题?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Clickmyad = New SqlClient.SqlDataAdapter("select * from yhxx where 1=2", myconn)
myad.Fill(myset, "yhxx")
myset.Tables("yhxx").PrimaryKey = Nothing
myset.Tables("yhxx").Rows.Clear()
myset.Tables("yhxx").Columns.Clear()
Dim mycol As New DataColumn
Dim myint As Int16
mycol.DataType = myint.GetType
mycol.ColumnName = "序号"
myset.Tables("yhxx").Columns.Add(mycol)
mystr = "select * from yhxx WHERE 时间 >= '" & Me.DateTimePicker1.Value.Date & "' and 时间 <= '" & Me.DateTimePicker2.Value.Date & "'and 单位 like '%" & TextBox2.Text & "%' and 整改情况 = '未整改'"
myad = New SqlClient.SqlDataAdapter(mystr, myconn)
myad.Fill(myset, "yhxx")
Me.DataGridView1.DataSource = myset.Tables("yhxx")
Dim myrow As DataRow
myint = 0
For Each myrow In myset.Tables("yhxx").Rows
myrow.BeginEdit()
myint += 1
myrow.Item("序号") = myint
myrow.EndEdit()
Next
End Sub
这个是form中的查询BUTTON代码。
Private Sub DataGridView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick
Dim mykey(1) As DataColumn
mykey(0) = myset.Tables("yhxx").Columns("id")
myset.Tables("yhxx").PrimaryKey = mykey
Dim myrow6 As DataRow
myrow6 = myset.Tables("yhxx").Rows.Find(Me.DataGridView1.Item(1, Me.DataGridView1.CurrentRow.Index).Value)
If myrow6 Is Nothing Then
myset.Tables("yhxx").PrimaryKey = mykey
myrow6 = myset.Tables("yhxx").Rows.Find(Me.DataGridView1.Item(1, Me.DataGridView1.CurrentRow.Index).Value)
Else
a = Me.DataGridView1.CurrentRow.Cells("专业").Value
b = myrow6.Item("单位")
c = myrow6.Item("时间")
d = myrow6.Item("地点")
l = myrow6.Item("班次")
f = myrow6.Item("检查人")
g = myrow6.Item("责任人")
h = myrow6.Item("限期时间")
i = myrow6.Item("整改意见")
j = myrow6.Item("存在隐患")
k = myrow6.Item(0)
End If
Dim w As yhzg = New yhzg()
w.Show()
End Sub
上段是DATAGRIDVIEW双击弹出新窗口代码。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Me.CheckBox1.Checked = True Then
Try
If Me.Txtid.Text = "" Then
MsgBox("不能修改!")
Else
Dim mycomm As SqlClient.SqlCommand = New SqlClient.SqlCommand("", myconn)
myconn.Open()
mycomm.CommandText = "update yhxx set 专业='" & Me.Txtzy.Text & "' where id=" & Me.Txtid.Text
mycomm.ExecuteNonQuery()
mycomm.CommandText = "update yhxx set 单位='" & Me.cmbdw.Text & "' where id=" & Me.Txtid.Text
mycomm.ExecuteNonQuery()
mycomm.CommandText = "update yhxx set 时间='" & Me.dtp1.Text & "' where id=" & Me.Txtid.Text
mycomm.ExecuteNonQuery()
mycomm.CommandText = "update yhxx set 地点='" & Me.txtdd.Text & "' where id=" & Me.Txtid.Text
mycomm.ExecuteNonQuery()
myconn.Close()
End If
Catch ex As Exception
End Try
Else
MsgBox("未成成功保存,如整改完成请选中是否整改!")
End If
MsgBox("保存成功!")
End Sub
上段是弹出新窗口后修改保存代码。
现在出现一个问题,就是当修改完成后如何实现DATAGRIDVIEW1的自动刷新?还一个问题就是修改完毕后,再点击最上面那个BUTTON1的代码时提示myset.Tables("yhxx").Columns.Clear()此列是主键的一部分,因此不能移除。,这是在最上面那段代码红色部分没加的时候,后来加了红色部分那段代码,现在却出现未将对象引用设置到对象的实例。这个是哪里的问题?请教 了
--------------------编程问答-------------------- http://topic.csdn.net/u/20071226/07/3e3d2d6b-5187-4744-937d-7f50c58ce935.html --------------------编程问答-------------------- 如果你想在修改完之后实现自动刷新..你可以在修改方法结束的end sub之前调用一次page_load(sender,e)方法。.
如果你想移除myset中的tables内容你可以直接用myset.clear()啊...
当你的myset.Tables("yhxx")中还有内容的时候在下面
myad = New SqlClient.SqlDataAdapter(mystr, myconn)
myad.Fill(myset, "yhxx")
Me.DataGridView1.DataSource = myset.Tables("yhxx")
这里应该是添加不进去的吧...
如果你想移除MYSET中的内容你加入myset.clear()再试试.. --------------------编程问答-------------------- 我是想自动刷新
补充:.NET技术 , VB.NET