Category: Visual Basic Programming
ADO.NET and Checking to see if record exist
What I am trying to do is this we have a couple branch offices that are looking to use a common database with the same program remotely. Now what I am doing is only pulling back one record at a time the one they search for. This will make it easier them pulling all 50,000+ records back at once. I have to figure out when someone wants to create a new record they will have to type in the ClientNumber first and see if it has already been entred if not then it allows them to create the record.
Not PHP code but is a code block so I used it.. *Grin*
Private Sub GetClientNumberQuery(ByVal stQuery As String, ByVal myClientNumber As String)
Try
selectNum = 0
daClients.Dispose()
dsClients.Dispose()
ClearTextBoxes()
daClients = New SqlDataAdapter(stQuery, cnClients)
Dim custCB As SqlCommandBuilder = New SqlCommandBuilder(daClients)
daClients.UpdateCommand = custCB.GetUpdateCommand
dsClients = New DataSet()
daClients.Fill(dsClients)
dsClients.Tables(0).TableName = "Clients"
SetNewClientNumber(dsClients.Tables("Clients"), selectNum, myClientNumber)
Catch _ex As Exception
MessageBox.Show(_ex.ToString)
Finally
Beep() ' Beep after error processing.
End Try
End Sub
Private Sub SetNewClientNumber(ByRef dt As DataTable, ByVal selectedNum As Integer, ByVal myClientNumber As String)
Dim drNew As DataRow
Dim iCount As Integer
Dim myTables As New ArrayList()
'Dim stString As String
Try
For iCount = 0 To 20
If dt.Rows(selectedNum).IsNull(iCount) Then
myTables.Add("")
Else
myTables.Add(dt.Rows(selectedNum).Item(iCount))
End If
Next
TextBox1.Text = myTables(1)
lblRecordID.Text = myTables(0)
TextBox2.Text = myTables(2)
ComboBox1.Text = myTables(3)
TextBox3.Text = myTables(4)
TextBox4.Text = myTables(5)
TextBox5.Text = myTables(6)
ComboBox2.Text = myTables(7)
TextBox6.Text = myTables(8)
TextBox7.Text = myTables(9)
TextBox8.Text = myTables(10)
ComboBox3.Text = myTables(11)
TextBox9.Text = myTables(12)
TextBox10.Text = myTables(13)
TextBox11.Text = myTables(14)
TextBox12.Text = myTables(15)
TextBox13.Text = myTables(16)
TextBox14.Text = myTables(17)
TextBox15.Text = myTables(18)
TextBox16.Text = myTables(19)
TextBox17.Text = myTables(20)
MessageBox.Show("Record already exist", "Record Exist", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch _ex As Exception
MessageBox.Show(_ex.ToString, "No Records Found", MessageBoxButtons.OK, MessageBoxIcon.Information)
ClearTextBoxes()
dsClients.Clear()
drNew = dsClients.Tables("Clients").NewRow
drNew.Item("ClientNumber") = myClientNumber
TextBox1.Text = myClientNumber
dsClients.Tables("Clients").Rows.Add(drNew)
EnableButtons(True)
bAddNew = True
Finally
Beep() ' Beep after error processing.
End Try
End Sub