我的代码:
Dim conn As ADODB.Connection
Dim sql As String
Dim rs1 As New ADODB.Recordset
Set conn = New ADODB.Connection
conn.ConnectionString = ConnectString
conn.Open '连接数据库
sql = "select * from clkc where 材料名称='" & Trim(txtfields(0).Text) & "' "
Set rs1 = conn.Execute(sql)
If rs1.EOF = True Then '如果没有的话就添加
rs1.Close
sql = "select * from clkc"
Set rs1 = conn.Execute(sql)
rs1.AddNew
rs1.Fields(0) = Trim(txtfields(0).Text)
For i = 1 To 2
If Trim(txtfields(i - 1).Text & "") = "" Then
rs1.Fields(i) = Null
Else
rs1.Fields(i) = Trim(txtfields(i).Text)
End If
Next i
rs1.Update
Else
' rs1.Edit '如果有的话就更新物资库存表中的信息(数量,金额)
rs1![重量] = Val(rs1![重量]) + Val(Trim(txtfields(1).Text))
rs1.Update
rs1.Close
End If --------------------编程问答-------------------- sql = "select * from clkc where 材料名称='" & Trim(txtfields(0).Text) & "' "
if rs1.state