wd006451
asked on
ADO.NET in a VB Module...
Hello, How do i convert the following code from this to ADO.NET
========================== ========== =====
Imports ADODB.CursorLocationEnum
Imports ADODB.CursorTypeEnum
Imports ADODB.LockTypeEnum
Module modGeneralDBCalls
Public conn_CMS As New ADODB.Connection
Public conn_cas_acc_usernames As New ADODB.Connection
Public ServerName As String = "localhost"
Public UserName As String = "root
Public PassWord As String = "password
Public db_name As String
Public tb_name As String
Public Function GetUserDB(ByRef U_ID As String, Optional ByVal Key As String = "", Optional ByVal keytext As String = "") As String
'This pulls up general info about the internal CMS user
On Error Resume Next
If conn_CMS.State = 1 Then conn_CMS.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver}" & ";SERVER=" & ServerName & ";DATABASE=" & db_name & ";UID=" & UserName & ";PWD=" & PassWord & ";OPTION=3"
conn_CMS.Open()
Dim rs As ADODB.Recordset
tb_name = "UserID"
db_name = "CMS"
rs = New ADODB.Recordset
rs.CursorLocation = ADODB.CursorLocationEnum.a dUseServer
Dim strData As String
strData = "U_ID = '" & U_ID & "'"
rs.Open("select * from " & tb_name, conn_CMS, ADODB.CursorTypeEnum.adOpe nStatic, ADODB.LockTypeEnum.adLockO ptimistic)
rs.Find(strData)
GetUserDB = rs.Fields(Key).Value
If keytext <> "" Then
rs.Fields(Key).Value = keytext
rs.Update()
End If
rs.Close()
conn_CMS.Close()
If Err.Number <> 0 Then GetUserDB = "<font color=""#FF0000"">Error: [" & Err.Number & "] " & Err.Description & "</font>"
End Function
End Module
==========================
Imports ADODB.CursorLocationEnum
Imports ADODB.CursorTypeEnum
Imports ADODB.LockTypeEnum
Module modGeneralDBCalls
Public conn_CMS As New ADODB.Connection
Public conn_cas_acc_usernames As New ADODB.Connection
Public ServerName As String = "localhost"
Public UserName As String = "root
Public PassWord As String = "password
Public db_name As String
Public tb_name As String
Public Function GetUserDB(ByRef U_ID As String, Optional ByVal Key As String = "", Optional ByVal keytext As String = "") As String
'This pulls up general info about the internal CMS user
On Error Resume Next
If conn_CMS.State = 1 Then conn_CMS.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver}" & ";SERVER=" & ServerName & ";DATABASE=" & db_name & ";UID=" & UserName & ";PWD=" & PassWord & ";OPTION=3"
conn_CMS.Open()
Dim rs As ADODB.Recordset
tb_name = "UserID"
db_name = "CMS"
rs = New ADODB.Recordset
rs.CursorLocation = ADODB.CursorLocationEnum.a
Dim strData As String
strData = "U_ID = '" & U_ID & "'"
rs.Open("select * from " & tb_name, conn_CMS, ADODB.CursorTypeEnum.adOpe
rs.Find(strData)
GetUserDB = rs.Fields(Key).Value
If keytext <> "" Then
rs.Fields(Key).Value = keytext
rs.Update()
End If
rs.Close()
conn_CMS.Close()
If Err.Number <> 0 Then GetUserDB = "<font color=""#FF0000"">Error: [" & Err.Number & "] " & Err.Description & "</font>"
End Function
End Module
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.