VB中用Mshflexgrid修改数据库并更新数据库问题 20
我用VB写了一段程序如下,运行后只有第一列数据更改不了,其他的数据都可以更改并更新数据库请问我要怎样修改程序才可以保证第一列数据也可以更改'设置text2与鼠标点中的表格...
我用VB写了一段程序如下,运行后只有第一列数据更改不了,其他的数据都可以更改并更新数据库
请问我要怎样修改程序才可以保证第一列数据也可以更改
'设置text2与鼠标点中的表格位置一致
Private Sub MSHFlexGrid1_RowColChange()
Dim x, y
Text2.Visible = True
For i = 1 To MSHFlexGrid1.Row
y = y + MSHFlexGrid1.RowHeight(i)
Text2.Top = y
Next i
For i = 0 To MSHFlexGrid1.Col
x = x + MSHFlexGrid1.ColWidth(i)
Text2.Left = x - MSHFlexGrid1.ColWidth(i)
Next i
Text2.Text = MSHFlexGrid1.Text
Text2.Width = MSHFlexGrid1.ColWidth(MSHFlexGrid1.Col)
Text2.Height = MSHFlexGrid1.RowHeight(MSHFlexGrid1.Row)
Text2.BackColor = RGB(250, 110, 120)
End Sub
'设置text2中修改的内容赋值给选中的表格
Private Sub Text2_Change()
MSHFlexGrid1.Text = Text2.Text
End Sub
'设置text2获得焦点后文本内容加亮
Private Sub Text2_GotFocus()
Text2.Visible = True
Text2.SelStart = 0
Text2.SelLength = Len(Text2.Text)
End Sub
'单击按钮更新修改过的数据并保存数据库
Private Sub Command2_Click()
Dim cnn2 As New ADODB.Connection
Dim i, j As Integer
Adodc2.ConnectionString = cnn2 'cnn2 数据库路径在公共变量中设置过
Adodc2.RecordSource = "select * from tb_employee"
cnn2.Open
For i = 1 To MSHFlexGrid1.Rows - 1
For j = 0 To MSHFlexGrid1.Cols - 1
Set rs2 = cnn2.Execute("update tb_employee set " + MSHFlexGrid1.TextMatrix(0, j) + "='" + MSHFlexGrid1.TextMatrix(i, j) + "' where number='" + MSHFlexGrid1.TextMatrix(i, 0) + "' ")
Next j
Next i
Set MSHFlexGrid1.DataSource = Adodc2
Adodc2.Refresh
MSHFlexGrid1.Refresh
Text2.Text = MSHFlexGrid1.Text
cnn2.Close
End Sub
上面代码是可以正常运行的,update更新数据那里是一行的,传上来才变成两行的 展开
请问我要怎样修改程序才可以保证第一列数据也可以更改
'设置text2与鼠标点中的表格位置一致
Private Sub MSHFlexGrid1_RowColChange()
Dim x, y
Text2.Visible = True
For i = 1 To MSHFlexGrid1.Row
y = y + MSHFlexGrid1.RowHeight(i)
Text2.Top = y
Next i
For i = 0 To MSHFlexGrid1.Col
x = x + MSHFlexGrid1.ColWidth(i)
Text2.Left = x - MSHFlexGrid1.ColWidth(i)
Next i
Text2.Text = MSHFlexGrid1.Text
Text2.Width = MSHFlexGrid1.ColWidth(MSHFlexGrid1.Col)
Text2.Height = MSHFlexGrid1.RowHeight(MSHFlexGrid1.Row)
Text2.BackColor = RGB(250, 110, 120)
End Sub
'设置text2中修改的内容赋值给选中的表格
Private Sub Text2_Change()
MSHFlexGrid1.Text = Text2.Text
End Sub
'设置text2获得焦点后文本内容加亮
Private Sub Text2_GotFocus()
Text2.Visible = True
Text2.SelStart = 0
Text2.SelLength = Len(Text2.Text)
End Sub
'单击按钮更新修改过的数据并保存数据库
Private Sub Command2_Click()
Dim cnn2 As New ADODB.Connection
Dim i, j As Integer
Adodc2.ConnectionString = cnn2 'cnn2 数据库路径在公共变量中设置过
Adodc2.RecordSource = "select * from tb_employee"
cnn2.Open
For i = 1 To MSHFlexGrid1.Rows - 1
For j = 0 To MSHFlexGrid1.Cols - 1
Set rs2 = cnn2.Execute("update tb_employee set " + MSHFlexGrid1.TextMatrix(0, j) + "='" + MSHFlexGrid1.TextMatrix(i, j) + "' where number='" + MSHFlexGrid1.TextMatrix(i, 0) + "' ")
Next j
Next i
Set MSHFlexGrid1.DataSource = Adodc2
Adodc2.Refresh
MSHFlexGrid1.Refresh
Text2.Text = MSHFlexGrid1.Text
cnn2.Close
End Sub
上面代码是可以正常运行的,update更新数据那里是一行的,传上来才变成两行的 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询