给一个字符串赋值,但是字符串的值为什么就不能改变呢?
部分代码如下:
Dim str_Sql as string
...
...
...
str_Sql = "delete table ..."
cn.Excute str_Sql,X
...
...
str_Sql = "insert table..."
cn.Excute str_Sql,X
...
...
...
第二个str_Sql 变量给它赋值的时候,有时候可以,但有时候为什么还是前面的那个值呀,想不明白啊,苦恼ing!求求大哥们帮我想想办法!谢啦!
部分代码如下:
Dim str_Sql as string
...
...
...
str_Sql = "delete table ..."
cn.Excute str_Sql,X
...
...
str_Sql = "insert table..."
cn.Excute str_Sql,X
...
...
...
第二个str_Sql 变量给它赋值的时候,有时候可以,但有时候为什么还是前面的那个值呀,想不明白啊,苦恼ing!求求大哥们帮我想想办法!谢啦!
'
'status = 1 Add Record
'status = 2 Edit Record
'
'////////////////////////////////////////////////////////////////////////////////Private Function Save_Record(ByVal status As Integer)
On Error Resume Next
Dim cn2 As ADODB.Connection
Dim clsAdo As New ClsComAdoDb
Dim adoRs As ADODB.Recordset
Dim str_Sql As String
Dim x As Integer
Dim i As Integer
Set cn2 = New ADODB.Connection
If status = 1 Then
str_Sql = "select tkno from tk_m where tkno = '" & Trim(txtTicketNo.Text) & "'"
Set adoRs = clsAdo.GetRec(str_Sql)
If Not adoRs.EOF Then
adoRs.Close
Set adoRs = Nothing
Set clsAdo = Nothing
MsgBox "The item has already exist,please input a different one!", vbInformation, "Add Item"
Exit Function
End If
adoRs.Close
Set adoRs = Nothing
Set clsAdo = Nothing
End If
Me.MousePointer = vbHourglass
cn2.Open Cn1
cn2.BeginTrans If status = 2 Then
str_Sql = "delete tk_d where tkno = '" & Trim(txtTicketNo.Text) & "'"
cn2.Execute str_Sql, x
If x = 0 Then
GoTo Error_line
End If
str_Sql = "delete tk_m where tkno = '" & Trim(txtTicketNo.Text) & "'"
cn2.Execute str_Sql, x
If x = 0 Then
GoTo Error_line
End If
End If
str_Sql = "insert tk_m(...)values(...)" ' 就这一句,当我作为add的时候可以,
'添加以后接着修改也行,当第二次从数据库中调出来再修改的时候就不能把值赋给str_Sql
'了。不知道是什么原因,查了好久!
cn2.Execute str_Sql, x
If x = 0 Then
GoTo Error_line
End If
Error_line:
cn2.RollbackTrans
cn2.Close
Set cn2 = Nothing
Me.MousePointer = vbDefault
MsgBox "Add Error:" & Err.Description, vbCritical, "Data"
End Function
str_Sql是个字符串变量,怎么可能不能赋值呢