VB.Net 2003 using ADODB.RECORDSET to determine record exist in SQL SERVER table to either Update or Create New Record.
Hi there,
I am new to Vb.Net and using VB.Net 2003 ADODB.RECORDSET. I am trying confirm record existence in SQL SERVER table in order to determine whether to CREATE NEW RECORD or UPDATE EXISTING RECORD using ADODB.RECORDSET. I copied an sample script from this Forum, modified it to suit IT DEPT requirements but it's not working
I need your Help.
Here are the script:
Option explicits On
Imports ADODB
Imports System.Data.SqlClient
Imports System.Data
Public Class clsAdoConnection
Private clsGvConnStr As String
Public Sub New()
clsGvConnStr &= ""
clsGvConnStr &= "Integrated Security=SSPI;"
clsGvConnStr &= "Data Source = KuahFamily;"
clsGvConnStr &= "Persist Security Info = False;"
clsGvConnStr &= "Initial Catalog=TravelDataBase"
End Sub
Public ReadOnly Property PropAdoConnection() As String
Get
Return clsGvConnStr
End Get
End Property
--------------------------------
Option explicit On
Imports ADODB
Imports System.Data.SqlClient
Imports System.Data
Private Sub FrmTESTRecordExist_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
connStr = clsAdoConn.PropAdoConnection
End Sub
------------------------------
Private Function FTestRecordExist()
Dim adoRst As New ADODB.Recordset
Dim adoConn As New Connection
Dim adoConnMode As Integer = ConnectModeEnum.adModeUnknown
Dim strSql As String = "Select * from TblTravelPriceRef where TravelCode = " & txtTravelCode.Text
adoConn.CursorLocation = CursorLocationEnum.adUseServer
adoConn.Open(connStr, "", "", adoConnMode)
Try
adoRst = adoConn.Execute(strSql)
If adoRst.EOF And adoRst.BOF Then
MessageBox.Show("Create New Record", "Test ADORST")
Else
MessageBox.Show("Update Existing Record", "Test ADORST")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
adoConn.Close()
End Try
End Function