After much convincing by other people, I have finally started trying to use ADO.NET instead of ADODB. Unfortunately, my lack of knowledge regarding these objects has left me broken in one area. I tried converting the area where I am checking for duplicate records to use ADO.NET by checking if a student filling out a form enters the same first name, last name, and program or major as another record in the database as per my instructions. Unfortunately, in the following code snippet, it is not behaving how I thought it should and I am unable to diagnose exactly where the problem might be just yet. I would appreciate any helpful information or pointers in the right direction on this issue that you might be able to give.
Here is the code in question:
I probably should have mentioned also that it never flags an error despite there being 'duplicate' records in the database at this point. Thank you for any pointers in the right direction or information/hints you might be able to give me in this matter!
Here is the code in question:
Code:
Try
Dim orion As New SqlConnection(strConn)
Dim sqlCmd As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(query, orion)
sqlCmd.Parameters.Add("@fName", System.Data.SqlDbType.NVarChar).Value = firstName.Text
sqlCmd.Parameters.Add("@lName", System.Data.SqlDbType.NVarChar).Value = lastName.Text
sqlCmd.Parameters.Add("@progMaj", System.Data.SqlDbType.NVarChar).Value = progMajor.SelectedValue.ToString
Dim dataAdapter As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter(sqlCmd)
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)
If (dataSet.Tables(0).CreateDataReader.HasRows) Then
'we already have this record in the database
errBlurb.Text &= "Already have this record." & vbCrLf
success = False
End If
Catch
errBlurb.Text &= "Error checking for duplicate records." & vbCrLf
success = False
End Try
Comment