求助,关于单元格显示问题
在sql servr中有一个表,表名为进货,其中的“序号”字段为int类型,为主键且自动加1。我在vb代码中写到:mshflexgrid1.textmatrix(1,1)=rs.flelds("序号").value为什么在mshflexgrid1的第一行第一列单元格中没有任何显示,请各位老师帮忙解决一下。谢谢 --------------------编程问答-------------------- 更全的代码贴出来
数据库连接、记录获得等等 --------------------编程问答-------------------- 示例,自己看吧
For i = 1 To rs.RecordCount
With MSHFlexGrid1
.Rows = .Rows + 1
.Row = i
.Col = 0
.Text = rs!编号
.Col = 1
.Text = rs!账号
.Col = 2
.Text = rs!金额
End With
rs.MoveNext
If rs.EOF Then Exit For
Next
--------------------编程问答-------------------- 第一行第一列应该是[0,0]吧 --------------------编程问答-------------------- Private Sub Form_Load()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=仓库管理5.11SQL"
rs.CursorType = adOpenDynamic
rs.LockType = adLockOptimistic
rs.Open "select * from 进货", cn
rs.AddNew
MSHFlexGrid1.TextMatrix(1, 1) = rs.Fields("序号").Value
rs.Update: rs.Close
End Sub
--------------------编程问答--------------------
如果要获取数据应该这样
Private Sub Form_Load()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=仓库管理5.11SQL"
rs.CursorType = adOpenDynamic
rs.LockType = adLockOptimistic
rs.Open "select * from 进货", cn
MSHFlexGrid1.TextMatrix(1, 1) = rs.Fields("序号").Value
rs.close
set rs=nothing
cn.close
set cn=nothing
End Sub
--------------------编程问答-------------------- 顶 --------------------编程问答-------------------- rs.AddNew 增加数据用
rs.Update 修改增加数据用 --------------------编程问答-------------------- Private Sub Form_Load()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=仓库管理5.11SQL"
rs.CursorType = adOpenDynamic
rs.LockType = adLockOptimistic
rs.Open "select * from 进货", cn
set mshflexgrid1.datasource=rs
rs.close
set rs=nothing
cn.close
set cn=nothing
End Sub
补充:VB , 数据库(包含打印,安装,报表)