I have a sub that checks table to see if row exists that match userinput (its checking on leave event of 2 textboxes custname and custnumb
sql server 2005 table with data
I also have filled dataset with the data
I dont want to filter the dataset at this point..
is there a way to just see if record exists in dataset?
if not whats the simplest way to return a count or boolean that a row exists?
just for ref here is my sub i think its clunky.. and doesnt work with select.. the insertcmd.executenonquery() part
sql server 2005 table with data
I also have filled dataset with the data
I dont want to filter the dataset at this point..
is there a way to just see if record exists in dataset?
if not whats the simplest way to return a count or boolean that a row exists?
just for ref here is my sub i think its clunky.. and doesnt work with select.. the insertcmd.executenonquery() part
VB.NET:
Public Sub CustomerCheckExists()
If custFail = True Or custFail = Nothing Then 'check CustomerName
Try
Dim sql1007 As String = "SELECT * FROM M8_Customers WHERE CustomerName ='" & Dispatch.txt_CustName_Customers.Text & "'"
sqlConn.Open()
Dim insertcmd As New SqlCommand(sql1007, sqlConn)
Dim count As Integer =
sqlConn.Close()
If count > 0 Then
Dispatch.lbl_custExist_Customers.ForeColor = Color.Red
Dispatch.lbl_custExist_Customers.Text = "Customer Name Exists =("
Dispatch.txt_CustName_Customers.Focus()
'MsgBox("Record already exists.", MsgBoxStyle.Critical, "Atention")
custFail = True
Exit Sub
Else
Dispatch.lbl_custExist_Customers.ForeColor = Color.Green
Dispatch.lbl_custExist_Customers.Text = " =) "
Dispatch.txt_CustName_Customers.ReadOnly = True
Dispatch.txt_CustNumber_Customers.Focus()
custFail = False
Exit Sub
End If
Catch ex As Exception
MsgBox(ex.Message & "In CustomersModule sql1007")
End Try
Else 'check CustomerNumber
Try
Dim sql1008 As String = "SELECT * FROM M8_Customers WHERE CustomerNumber ='" & Dispatch.txt_CustNumber_Customers.Text & "'"
sqlConn.Open()
Dim insertcmd As New SqlCommand(sql1008, sqlConn)
Dim count As Integer = insertcmd.ExecuteNonQuery()
sqlConn.Close()
If count > 0 Then
Dispatch.lbl_custNumbExists_Customers.ForeColor = Color.Red
Dispatch.lbl_custNumbExists_Customers.Text = "Customer Name Exists =("
Dispatch.txt_CustNumber_Customers.Focus()
'MsgBox("Record already exists.", MsgBoxStyle.Critical, "Atention")
Exit Sub
Else
Dispatch.lbl_custNumbExists_Customers.ForeColor = Color.Green
Dispatch.lbl_custNumbExists_Customers.Text = " =) "
Dispatch.txt_Contact_Customers.Focus()
Dispatch.txt_CustNumber_Customers.ReadOnly = True
custFail = False
Exit Sub
End If
Catch ex As Exception
MsgBox(ex.Message & "In CustomersModule sql1008")
End Try
End If
End Sub