vb 仓库出库代码的问题

来源:百度知道 编辑:UC知道 时间:2024/05/29 07:35:30
Dim conn As Adodb.Connection
Dim sql As Adodb.Command
Dim StrConn As String
Private Sub Command1_Click()
Dim use As String
Form4.Adodc1.RecordSource = "select 数量 from 产品 where 食品名称='" + DataCombo1.Text + "'"
use = Form4.Adodc1.Recordset.Fields(6).Value
Dim a, b As Long
a = Text1.Text: b = use
If a > b Then
MsgBox "出库失败,不能出库" + Text1.Text + ",库存数量为" + Str(use)
Exit Sub
End If
sql = "update 产品 set 数量 = " & b & " - '" + Text1.Text + "' where 食品名称='" + DataCombo1.Text + "'"
conn.Execute.strsql
Adodc1.Recordset.AddNew
End Sub

Private Sub Form_Load()
Set conn = New Adodb.Connection
StrConn = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=D:\a\a1.mdb"
conn.Open StrConn
End Sub

显示说sql = 属性的使用无效 急!!!线上等
还有一个问题 Form4.Ado

用conn.Execute开启的资料集合是唯读的,无法使用新增资料功能。
建议用rs.open写法如下

Dim conn As Adodb.Connection
Dim rs As Adodb.Recordset
.....
....
......

Set rs = New Adodb.Recordset
sql = "update 产品 set 数量 = " & b & " - '" + Text1.Text + "' where 食品名称='" + DataCombo1.Text + "'"
rs.Open sql, conn, adOpenKeyset, adLockPessimistic
Adodc1.Recordset.AddNew

-----------

Private Sub Form_Load()
Set conn = New Adodb.Connection
StrConn = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=D:\a\a1.mdb"
conn.Open StrConn
rs.CursorLocation = adUseClient
End Sub

conn.Execute.strsql 这里的问题

建议你最好不要用VB自带的控件,那个控件很难用的