大家帮我看看 到底哪里不对了 老提示记录 对象打开时,不允许操作 我已添加了个rs.close 然后又提示 对象关闭时,不允许操作 救命啊
Private Sub Command2_Click()
Dim a As Integer
If combo1.Text = "" Or combo2.Text = "" Or text4.Text = "" Or IsNumeric(text4.Text) = False Or text5.Text = "" Or IsNumeric(text5.Text) = False Then
MsgBox ("请检查详细记录是否为空,或是否输入的是数字!")
Else
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset
db.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=lzjc;Data Source=."
db.Open
rs.Open "insert into lingB(Aid,类别,名称,数量,单价) values('" & Trim(text1.Text) & "','" & Trim(combo1.Text) & "','" & Trim(combo2.Text) & "','" & Trim(text4.Text) & "','" & Trim(text5.Text) & "')", db, adOpenStatic, adLockReadOnlyrs.Open "select sum(金额) as 合计 from lingB where lingB.Aid='" & Trim(text1.Text) & "'", db, adOpenStatic, adLockReadOnly
Text3.Text = Trim(rs.Fields("合计").Value)rs.Open "select 类别,名称,数量,单价,金额 from lingB where Aid= '" & Trim(text1.Text) & "'", db, adOpenStatic, adLockReadOnly
Set DataGrid1.DataSource = rs
rs.Close
End If
combo1.Text = ""
combo2.Text = ""
text4.Text = ""
text5.Text = ""
End Sub
Private Sub Command2_Click()
Dim a As Integer
If combo1.Text = "" Or combo2.Text = "" Or text4.Text = "" Or IsNumeric(text4.Text) = False Or text5.Text = "" Or IsNumeric(text5.Text) = False Then
MsgBox ("请检查详细记录是否为空,或是否输入的是数字!")
Else
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset
db.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=lzjc;Data Source=."
db.Open
rs.Open "insert into lingB(Aid,类别,名称,数量,单价) values('" & Trim(text1.Text) & "','" & Trim(combo1.Text) & "','" & Trim(combo2.Text) & "','" & Trim(text4.Text) & "','" & Trim(text5.Text) & "')", db, adOpenStatic, adLockReadOnlyrs.Open "select sum(金额) as 合计 from lingB where lingB.Aid='" & Trim(text1.Text) & "'", db, adOpenStatic, adLockReadOnly
Text3.Text = Trim(rs.Fields("合计").Value)rs.Open "select 类别,名称,数量,单价,金额 from lingB where Aid= '" & Trim(text1.Text) & "'", db, adOpenStatic, adLockReadOnly
Set DataGrid1.DataSource = rs
rs.Close
End If
combo1.Text = ""
combo2.Text = ""
text4.Text = ""
text5.Text = ""
End Sub
后rs不要closeinsert后select sum后分别加一个rs.close
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset
db.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=lzjc;Data Source=."
db.Open
db.Execute("insert into lingB(Aid,类别,名称,数量,单价) values('" & Trim(text1.Text) & "','" & Trim(combo1.Text) & "','" & Trim(combo2.Text) & "','" & Trim(text4.Text) & "','" & Trim(text5.Text) & "')") rs.Open "select sum(金额) as 合计 from lingB where lingB.Aid='" & Trim(text1.Text) & "'", db, adOpenStatic, adLockReadOnly
Text3.Text = Trim(rs.Fields("合计").Value)
rs.Close rs.Open "select 类别,名称,数量,单价,金额 from lingB where Aid= '" & Trim(text1.Text) & "'", db, adOpenStatic, adLockReadOnly
Set DataGrid1.DataSource = rs
rs.Close
End If
Set DataGrid1.DataSource = rs
rs.Close
直接没运行 我试过了
可以
MsgBox rs.RecordCount 出来看看吗?
Dim a As Integer
If combo1.Text = "" Or combo2.Text = "" Or text4.Text = "" Or IsNumeric(text4.Text) = False Or text5.Text = "" Or IsNumeric(text5.Text) = False Then
MsgBox ("请检查详细记录是否为空,或是否输入的是数字!")
Else
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset
db.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=lzjc;Data Source=."
db.Opendb.execute( "insert into lingB(Aid,类别,名称,数量,单价) values('" & Trim(text1.Text) & "','" & Trim(combo1.Text) & "','" & Trim(combo2.Text) & "','" & Trim(text4.Text) & "','" & Trim(text5.Text) & "')")rs.Open "select sum(金额) as 合计 from lingB where lingB.Aid='" & Trim(text1.Text) & "'", db, adOpenStatic, adLockReadOnly
Text3.Text = Trim(rs.Fields("合计").Value)
rs.closers.Open "select 类别,名称,数量,单价,金额 from lingB where Aid= '" & Trim(text1.Text) & "'", db, adOpenStatic, adLockReadOnly
Set DataGrid1.DataSource = rs
rs.Close
End If
combo1.Text = ""
combo2.Text = ""
text4.Text = ""
text5.Text = ""
End Sub
在运行的时候弹出来 上面写 1 我点确定 就没有了
但我方在SET datagrid之后的话 就神了
也弹出 1 但是datagrid 里有内容了 但我点确定 datagrid里就没内容了
后rs不要close