vb连接sql数据库,用文本框里的字符串做if判断,取不出值是怎么回事?会的小伙伴们能帮下忙吗
代码如下:DimobjCnAsConnection,objRSAsRecordsetPrivateSubForm_Load()OnErrorGoToDealErrorDi...
代码如下:
Dim objCn As Connection, objRS As Recordset
Private Sub Form_Load()
On Error GoTo DealError
Dim objCn As New Connection
With objCn
.Provider = "SQLOLEDB"
.ConnectionString = "User ID=sa;PWD=****;Data Source=(LOCAL);" & _
"Initial Catalog=salarysystem"
.Open
End With
Set objRS = New Recordset
Set objRS.ActiveConnection = objCn
objRS.CursorLocation = adUseClient
objRS.CursorType = adOpenDynamic
objRS.LockType = adLockBatchOptimistic
strsql = "SELECT * FROM 员工信息"
objRS.Open strsql
ShowCurrentRecord
Exit Sub
DealError:
msg = "连接数据库执行出错,错误信息如下:" & vbCrLf & Err.Description
Showerror msg
End Sub
Private Sub ShowCurrentRecord()
On Error GoTo DealError
txtTitle = objRS!职称
If txtTitle.Text = "中级" Then
txtTest.Text = txtTitle.Text
End If
exit Sub
DealError:
msg = "显示当前信息执行出错,错误信息如下:" & vbCrLf & Err.Description
Showerror msg
End Sub
错误为:txtTitle文本框里的内容为”中级”,但是txtTest文本框里的内容无值 展开
Dim objCn As Connection, objRS As Recordset
Private Sub Form_Load()
On Error GoTo DealError
Dim objCn As New Connection
With objCn
.Provider = "SQLOLEDB"
.ConnectionString = "User ID=sa;PWD=****;Data Source=(LOCAL);" & _
"Initial Catalog=salarysystem"
.Open
End With
Set objRS = New Recordset
Set objRS.ActiveConnection = objCn
objRS.CursorLocation = adUseClient
objRS.CursorType = adOpenDynamic
objRS.LockType = adLockBatchOptimistic
strsql = "SELECT * FROM 员工信息"
objRS.Open strsql
ShowCurrentRecord
Exit Sub
DealError:
msg = "连接数据库执行出错,错误信息如下:" & vbCrLf & Err.Description
Showerror msg
End Sub
Private Sub ShowCurrentRecord()
On Error GoTo DealError
txtTitle = objRS!职称
If txtTitle.Text = "中级" Then
txtTest.Text = txtTitle.Text
End If
exit Sub
DealError:
msg = "显示当前信息执行出错,错误信息如下:" & vbCrLf & Err.Description
Showerror msg
End Sub
错误为:txtTitle文本框里的内容为”中级”,但是txtTest文本框里的内容无值 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询