Results 1 to 6 of 6

Thread: [2008] Data type mismatch in criteria expression. URGENT

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    258

    [2008] Data type mismatch in criteria expression. URGENT

    Alright I fixed my last problem but now I'm getting this error only when Editing:

    Data type mismatch in criteria expression.

    Here's my Code:

    Table Create:
    vb Code:
    1. Public Sub CreateDatabase()
    2.         Dim DB As New ADOX.Catalog()
    3.         DB.Create(Connection.ConnectionString)
    4.         Connection.Open()
    5.         SQL = "CREATE TABLE [Students] ([CIndex] AutoIncrement, [StudentID] TEXT, [LastName] TEXT, [FirstName] TEXT, [Grade] TEXT, [Gender] TEXT, [BirthDate] TEXT, [PhoneNum] TEXT, [AddressOne] TEXT, [AddressTwo] TEXT, [EmailOne] TEXT, [EmailTwo] TEXT, [Notes] TEXT)"
    6.         Command = New OleDbCommand(SQL, Connection)
    7.         Command.ExecuteNonQuery()
    8.     End Sub


    Student Edit:
    vb Code:
    1. Public Sub Students_Edit()
    2.         Students_SQLSelect()
    3.         Adapter.UpdateCommand = New OleDbCommand("UPDATE [Students] SET StudentID = @ID, LastName = @LN, FirstName = @FN, Gender = @Gen, BirthDate = @Birth, [Phone#] = @Phone, Address1 = @AD1, Address2 = @AD2, Email1 = @E1, Email2 = @E2, Notes = @Notes WHERE CIndex = @CIndex")
    4.         Adapter.UpdateCommand.Connection = Connection
    5.         Connection.Open()
    6.         With Adapter.UpdateCommand
    7.             .Parameters.Add("@ID", OleDbType.VarChar, 10, "StudentID")
    8.             .Parameters.Add("@LN", OleDbType.VarChar, 75, "LastName")
    9.             .Parameters.Add("@FN", OleDbType.VarChar, 75, "FirstName")
    10.             .Parameters.Add("@Grade", OleDbType.VarChar, 2, "Grade")
    11.             .Parameters.Add("@Gen", OleDbType.VarChar, 6, "Gender")
    12.             .Parameters.Add("@Birth", OleDbType.VarChar, 100, "BirthDate")
    13.             .Parameters.Add("@Phone", OleDbType.VarChar, 25, "[Phone#]")
    14.             .Parameters.Add("@AD1", OleDbType.VarChar, 100, "Address1")
    15.             .Parameters.Add("@AD2", OleDbType.VarChar, 100, "Address2")
    16.             .Parameters.Add("@E1", OleDbType.VarChar, 100, "Email1")
    17.             .Parameters.Add("@E2", OleDbType.VarChar, 100, "Email2")
    18.             .Parameters.Add("@Notes", OleDbType.VarChar, 500, "Notes")
    19.             .Parameters.Add("@CIndex", OleDbType.Integer, 5, "CIndex")
    20.         End With
    21.         With frmStudentsAdd
    22.             Adapter.Fill(DS)
    23.             Dim DRow As DataRow
    24.             DRow = DS.Tables(0).Rows(frmStudents.RIndex)
    25.             MsgBox(DRow.Item("StudentID"))
    26.             DRow.BeginEdit()
    27.             DRow("StudentID") = .txtStudentID.Text
    28.             DRow("LastName") = .txtLastName.Text
    29.             DRow("FirstName") = .txtFirstName.Text
    30.             DRow("Grade") = .txtGrade.Text
    31.             If .rbMale.Checked Then
    32.                 DRow.Item("Gender") = "Male"
    33.             ElseIf .rbFemale.Checked Then
    34.                 DRow.Item("Gender") = "Female"
    35.             End If
    36.             DRow("BirthDate") = .dtpBirth.Value.ToShortDateString
    37.             DRow("Phone#") = .txtPhone.Text
    38.             DRow("Address1") = .txtAddressOne.Text
    39.             DRow("Address2") = .txtAddressTwo.Text
    40.             DRow("Email1") = .txtEmailOne.Text
    41.             DRow("Email2") = .txtEmailTwo.Text
    42.             DRow("Notes") = .txtNotes.Text
    43.             DRow.EndEdit()
    44.             Adapter.Update(DS)
    45.             DS.AcceptChanges()
    46.         End With
    47.         Connection.Close()
    48.         Students_LoadToList()
    49.     End Sub

    It inserts fine when adding but the moment I try to Edit it, I get that error.

    EDIT:

    Hmm, I seem to have fixed it, by adding text to all the textboxes. How can I do this without having to add to add textboxes, and When I have Data in all the Textboxes, Everything from Column Genedr is Shifted Over 1.
    Last edited by Wesley008; Nov 9th, 2008 at 03:29 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width