【vb+sql】选中datagrid的某一行,使其第一个单元格的内容显示在text文本框中?
比如这个情况,我就需要选中第一行的时候,text1.text=1001我已经编写的代码:OptionExplicitPrivateSubCommand1_Click()D...
比如这个情况,我就需要选中第一行的时候,text1.text=1001
我已经编写的代码:
Option Explicit
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim rs_findsp As New ADODB.Recordset
cn.CursorLocation = adUseClient
cn.ConnectionString = "driver={SQL Server};server=(local);uid=;pwd=;database=market"
cn.Open
rs_findsp.Open ("select 商品号,商品名称,单价,商品类型,厂商,库存量 from 商品表 where 商品类型= '" & Combo1.Text & "' "), cn, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = rs_findsp
DataGrid1.Refresh
DataGrid1.AllowAddNew = False
DataGrid1.AllowDelete = False
DataGrid1.AllowUpdate = False
Set DataGrid1.DataSource = rs_findsp
End Sub
Private Sub Form_Load()
Combo1.AddItem "食品"
Combo1.AddItem "饮料"
Combo1.AddItem "日用品"
Combo1.AddItem "乳制品"
Combo1.AddItem "香烟"
End Sub
实在是不会写,毕竟初学者。求教!万分感谢! 展开
我已经编写的代码:
Option Explicit
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim rs_findsp As New ADODB.Recordset
cn.CursorLocation = adUseClient
cn.ConnectionString = "driver={SQL Server};server=(local);uid=;pwd=;database=market"
cn.Open
rs_findsp.Open ("select 商品号,商品名称,单价,商品类型,厂商,库存量 from 商品表 where 商品类型= '" & Combo1.Text & "' "), cn, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = rs_findsp
DataGrid1.Refresh
DataGrid1.AllowAddNew = False
DataGrid1.AllowDelete = False
DataGrid1.AllowUpdate = False
Set DataGrid1.DataSource = rs_findsp
End Sub
Private Sub Form_Load()
Combo1.AddItem "食品"
Combo1.AddItem "饮料"
Combo1.AddItem "日用品"
Combo1.AddItem "乳制品"
Combo1.AddItem "香烟"
End Sub
实在是不会写,毕竟初学者。求教!万分感谢! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |