VB怎么修改数据库指定单元格里的数据
1个回答
展开全部
给你一个例子
Dim Conn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Rs.Open "SELECT * FROM 报警记录 where " & Te.Tag & "='" & Text1.Text & "'", Conn
If Rs.RecordCount = 0 Then
MsgBox vbCrLf & "“" & Rs.Fields(0) & "”查找失败!", vbInformation, " 提 示"
Rs.Close
Rs.Open "select * from 报警记录", Conn, adOpenStatic, adLockOptimistic
End If
Set DataGrid1.DataSource = Rs
For Each Col In DataGrid1.Columns '修改列表
If Col.DataField = "序号" Or Col.DataField = "备注" Then Col.Visible = False '隐藏不想显示的字段
Next Col
DataGrid1.Columns(11).Caption = "电压"‘替换显示将数据库里的字段
if Rs.Fields(4)="10" then msgbox "数值过低!"'第5(从0开始)个单元格数值
For I = 0 To 14
DataGrid1.Columns(I).Caption = Space(((DataGrid1.Columns(I).Width - Len(DataGrid1.Columns(I).Caption) * 150) \ 2) \ 150) & DataGrid1.Columns(I).Caption '标题居中
DataGrid1.Columns(I).Alignment = dbgCenter
Next
Dim Conn As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Rs.Open "SELECT * FROM 报警记录 where " & Te.Tag & "='" & Text1.Text & "'", Conn
If Rs.RecordCount = 0 Then
MsgBox vbCrLf & "“" & Rs.Fields(0) & "”查找失败!", vbInformation, " 提 示"
Rs.Close
Rs.Open "select * from 报警记录", Conn, adOpenStatic, adLockOptimistic
End If
Set DataGrid1.DataSource = Rs
For Each Col In DataGrid1.Columns '修改列表
If Col.DataField = "序号" Or Col.DataField = "备注" Then Col.Visible = False '隐藏不想显示的字段
Next Col
DataGrid1.Columns(11).Caption = "电压"‘替换显示将数据库里的字段
if Rs.Fields(4)="10" then msgbox "数值过低!"'第5(从0开始)个单元格数值
For I = 0 To 14
DataGrid1.Columns(I).Caption = Space(((DataGrid1.Columns(I).Width - Len(DataGrid1.Columns(I).Caption) * 150) \ 2) \ 150) & DataGrid1.Columns(I).Caption '标题居中
DataGrid1.Columns(I).Alignment = dbgCenter
Next
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |