locked
Access error Data Type Mismatch In Criteria Expression RRS feed

  • Question

  • User1250726567 posted

    Hi, I have a very annoying problem with a SQL request with VB.netthe thing is I think because I encrypt my Strings and some special characters may appear like =, / and \. Moreover, Visual studio does not catch this error by default. I have to use a try catch to get the error message because unless it just skips the lines after the adapt.Fill(Dset, "Logins") till the end of the sub. How can I escape those special characters?

    Dim provider As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
            Dim source As String = "DATA SOURCE=" & Directory.GetCurrentDirectory() & "\" & "Logins.mdb;"
            BDConnexion.ConnectionString = provider & source
            BDConnexion.Open()
            Dim SQLrequest As String = "Select * FROM Logins WHERE 1=@name"
            Dim command As New OleDbCommand(SQLrequest, BDConnexion)
            command.Parameters.AddWithValue("name", LoginForm.AES_Encrypt(user, KEY))
            Dim adapt As New OleDbDataAdapter(command)
            Try
                adapt.Fill(Dset, "Logins") /*-------------------------here is the line that bugs------*/
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try

            PictureBox1.ImageLocation = Directory.GetCurrentDirectory() + "\pics\" + LoginForm.AES_Decrypt(Dset.Tables("Logins").Rows(2).Item(0).ToString(), KEY) + ".png"
            LblBienvenue.Text = "Bienvenue " + LoginForm.AES_Decrypt(Dset.Tables("Logins").Rows(0).Item(0).ToString(), KEY)

    Sunday, April 1, 2012 8:25 PM

Answers

  • User197322208 posted

    0, 1, 2, 3 are my columns name and not integers

    wow. Why do you name like this?!

    anyway, put

    [1] = @name

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 2, 2012 8:30 AM

All replies

  • User197322208 posted

    WHERE 1=@name

    Who is 1? It is a column? And why do you compare int with string?

    Monday, April 2, 2012 1:11 AM
  • User1250726567 posted

    yes sorry about that 0, 1, 2, 3 are my columns name and not integers

    Monday, April 2, 2012 8:17 AM
  • User197322208 posted

    0, 1, 2, 3 are my columns name and not integers

    wow. Why do you name like this?!

    anyway, put

    [1] = @name

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 2, 2012 8:30 AM
  • User1250726567 posted

    thanks or sorry for the newbie misakes!

    Monday, April 2, 2012 10:17 AM