System.Data.OleDb.OleDbException: Data type mismatch in criteria expression. HELP ME :)

Hello

this is my select code

1     Dim ConnString1 As String = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|Nwind2003(Good).mdb"
2            Dim sqlstring3 As String = "SELECT * FROM customers WHERE CustomerID= '" & CustomerID & "'"
3            Dim conn2 As New OleDbConnection(ConnString1)
4 Dim cmd2 As New OleDbCommand(sqlstring3, conn2)
5 cmd2.CommandType = CommandType.Text
6 Response.Write(sqlstring3)
7
8 conn2.Open()
9 Dim reader As OleDbDataReader = cmd2.ExecuteReader()
10
11 While reader.Read
12 Label1.Text = reader("
ContactName").ToString
13 Label2.Text = reader("
Customerid").ToString
14 TextBox10.Text = reader("
fax").ToString
15 TextBox9.Text = reader("
phone").ToString
16 TextBox7.Text = reader("
country").ToString
17 TextBox6.Text = reader("
postacode").ToString
18 TextBox8.Text = reader("
region").ToString
19 TextBox5.Text = reader("
city").ToString
20 TextBox4.Text = reader("
address").ToString
21 TextBox2.Text = reader("
ContactTitle").ToString
22 TextBox3.Text = reader("
ContactName").ToString
23 TextBox1.Text = reader("
CompanyName").ToString
24 End While 25
26 conn2.Close()
27  

but there is an error on line 9 (in full code it is line 20)

Data type mismatch in criteria expression.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Data type mismatch in criteria expression.

Source Error:

Line 18:         
Line 19: conn2.Open()
Line 20: Dim reader As OleDbDataReader = cmd2.ExecuteReader()
Line 21:
Line 22: While reader.Read
 

Can someone help me ?

 

TNX  

0
alex188
8/1/2008 7:12:04 AM
asp.net.access-datasource 4679 articles. 0 followers. Follow

10 Replies
1226 Views

Similar Articles

[PageSpeed] 15

What is the data type of CustomerID in the database? Is it an integer or a string? If it's an integer, get rid of the single quotes you're surrounding it with in the SQL statement.

Don


Don Kiely, MCP, MCSD
In the Last Frontier, Interior Alaska
Please post questions and replies to the forum! And remember to MARK AS ANSWER when someone definitively answers a question or resolves a problem!
0
donkiely
8/1/2008 7:15:32 AM

 

in db it is AutoNumber in the code it set as integer
0
alex188
8/1/2008 7:54:58 AM

Rather than messing around with delimiters, use parameters.  That will resolve the issue: http://www.mikesdotnetting.com/Article.aspx?ArticleID=26

 


Regards Mike
[MVP - ASP/ASP.NET]
My site
0
Mikesdotnetting
8/1/2008 11:38:33 AM

In the beginning i  used parameters, and really flowed your article, but there was some issues and no one was able to help, you can see it on my post

http://forums.asp.net/p/1290934/2509043.aspx#2509043

 here is the code

 

1    Dim ConnString1 As String = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|Nwind2003(Good).mdb"
2                Dim sqlstring3 As String = "SELECT * FROM customers WHERE CustomerID= ?"
3                Dim conn2 As New OleDbConnection(ConnString1)
4                Dim cmd2 As New OleDbCommand(sqlstring3, conn2)
5                cmd2.CommandType = CommandType.Text
6                cmd2.Parameters.AddWithValue("CustomerID", CustomerID)
7           
8                conn2.Open()
9                Dim reader As OleDbDataReader = cmd2.ExecuteReader()
10           
11               Label1.Text = reader("ContactName").ToString
12               Label2.Text = reader("Customerid").ToString
13               TextBox10.Text = reader("fax").ToString
14               TextBox9.Text = reader("phone").ToString
15               TextBox7.Text = reader("country").ToString
16               TextBox6.Text = reader("postacode").ToString
17               TextBox8.Text = reader("region").ToString
18               TextBox5.Text = reader("city").ToString
19               TextBox4.Text = reader("address").ToString
20               TextBox2.Text = reader("ContactTitle").ToString
21               TextBox3.Text = reader("ContactName").ToString
22               TextBox1.Text = reader("CompanyName").ToString

 this code did not work at all !!!

no error and there no respond

 

0
alex188
8/1/2008 11:49:56 AM

Can you post all your database related code without line numbers?

 


Regards Mike
[MVP - ASP/ASP.NET]
My site
0
Mikesdotnetting
8/1/2008 12:11:07 PM

 <%@ Page Language="VB"  Debug="true" Title="Untitled Page"    %>

<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.OleDb" %>

<script runat="server">
    Dim CustomerID As Integer

    Protected Sub get_data()
        Dim ConnString1 As String = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|Nwind2003(Good).mdb"
        Dim sqlstring3 As String = "SELECT * FROM customers WHERE CustomerID= '" & CustomerID & "'"
        Dim conn2 As New OleDbConnection(ConnString1)
        Dim cmd2 As New OleDbCommand(sqlstring3, conn2)
        cmd2.CommandType = CommandType.Text
        '  cmd2.Parameters.AddWithValue("CustomerID", CustomerID)
        Response.Write(sqlstring3)
        
        conn2.Open()
        Dim reader As OleDbDataReader = cmd2.ExecuteReader()
            
        While reader.Read
            Label1.Text = reader("ContactName").ToString
            Label2.Text = reader("Customerid").ToString
            TextBox10.Text = reader("fax").ToString
            TextBox9.Text = reader("phone").ToString
            TextBox7.Text = reader("country").ToString
            TextBox6.Text = reader("postacode").ToString
            TextBox8.Text = reader("region").ToString
            TextBox5.Text = reader("city").ToString
            TextBox4.Text = reader("address").ToString
            TextBox2.Text = reader("ContactTitle").ToString
            TextBox3.Text = reader("ContactName").ToString
            TextBox1.Text = reader("CompanyName").ToString
        End While
      
        conn2.Close()
       
    End Sub
    
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
 
        Dim ConnString As String = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|Nwind2003(Good).mdb"
        Dim sqlstring As String = "INSERT INTO Customers (Fax, Phone, Country, PostalCode, Region, City, Address, ContactTitle, ContactName, CompanyName) VALUES (?,?,?,?,?,?,?,?,?,?)"
        Dim sqlstring2 As String = "Select @@Identity"
        Dim conn As New OleDbConnection(ConnString)
        Dim cmd As New OleDbCommand(sqlstring, conn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("fax", TextBox10.Text)
        cmd.Parameters.AddWithValue("phone", TextBox9.Text)
        cmd.Parameters.AddWithValue("country", TextBox7.Text)
        cmd.Parameters.AddWithValue("postacode", TextBox6.Text)
        cmd.Parameters.AddWithValue("region", TextBox8.Text)
        cmd.Parameters.AddWithValue("city", TextBox5.Text)
        cmd.Parameters.AddWithValue("address", TextBox4.Text)
        cmd.Parameters.AddWithValue("ContactTitle", TextBox2.Text)
        cmd.Parameters.AddWithValue("ContactName", TextBox3.Text)
        cmd.Parameters.AddWithValue("CompanyName", TextBox1.Text)
        
        Button3.Visible = True
        Button1.Visible = False
        
       
        conn.Open()
        cmd.ExecuteNonQuery()
        cmd.CommandText = sqlstring2
        CustomerID = cmd.ExecuteScalar()

            
        Dim ConnString1 As String = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|Nwind2003(Good).mdb"
        Dim sqlstring3 As String = "SELECT * FROM customers WHERE CustomerID= ?"
        Dim conn2 As New OleDbConnection(ConnString1)
        Dim cmd2 As New OleDbCommand(sqlstring3, conn2)
        cmd2.CommandType = CommandType.Text
        cmd2.Parameters.AddWithValue("CustomerID", CustomerID)
        Response.Write(sqlstring3)
        
        conn2.Open()
        Dim reader As OleDbDataReader = cmd2.ExecuteReader()
            
        While reader.Read
            Label1.Text = reader("ContactName").ToString
            Label2.Text = reader("Customerid").ToString
            TextBox10.Text = reader("fax").ToString
            TextBox9.Text = reader("phone").ToString
            TextBox7.Text = reader("country").ToString
            TextBox6.Text = reader("postacode").ToString
            TextBox8.Text = reader("region").ToString
            TextBox5.Text = reader("city").ToString
            TextBox4.Text = reader("address").ToString
            TextBox2.Text = reader("ContactTitle").ToString
            TextBox3.Text = reader("ContactName").ToString
            TextBox1.Text = reader("CompanyName").ToString
        End While
      
        conn2.Close()
        conn.Close()
        
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim datakeyvalueinsecondpage As Integer = Request.QueryString("id")
        
        If datakeyvalueinsecondpage > 0 Then
            CustomerID = datakeyvalueinsecondpage
            get_data()
        End If
        
        Label1.Text = datakeyvalueinsecondpage
    End Sub
</script>

<html dir="rtl">

<body>

<form runat ="server">

    <p>
        <img alt="" src="IMG/add_user-64.png" style="width: 64px; height: 64px" /></p>




    <p>
        <br />
        <span
                                        
            style="color: #22354F; font-weight: bold; font-size: x-large; font-family: Tahoma;">
        כרטיס לקוח</span></p>
    <p>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
&nbsp;<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
    </p>


    <div style="height: 229px; width: 100%" dir="rtl">

    <table align="center"  dir="rtl" style="width: 98%"
           >
            <tr>
                <td style="font-size: 10pt; color: #FFFFFF; font-weight: bold; background-color: #303F53"
                    width="25%">
                    <b>שם חברה<font size="2"><span style="color: #FFFFFF"><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="&#1513;&#1491;&#1492;: &#1513;&#1501; &#1495;&#1489;&#1512;&#1492; &#1495;&#1493;&#1489;&#1492;"
                                style="font-size: x-small"><b><font size="2"><span
                        style="color: #FFFFFF">*</span></font></b></asp:RequiredFieldValidator>
                            </span></font></b>
                </td>
                <td style="font-size: 10pt; color: #FFFFFF; background-color: #303F53"
                    width="25%">
                    <b>שם איש הקשר<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
                                ControlToValidate="TextBox3" ErrorMessage="&#1513;&#1491;&#1492;: &#1513;&#1501; &#1488;&#1497;&#1513; &#1511;&#1513;&#1512; &#1495;&#1493;&#1489;&#1492;">*</asp:RequiredFieldValidator>
                            </b>
                </td>
                <td style="font-size: 10pt; background-color: #303F53" width="25%">
                    <span style="color: #FFFFFF"><b>תיאור איש קשר
                            <span style="font-size: x-small">
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
                                ControlToValidate="TextBox2" ErrorMessage="&#1513;&#1491;&#1492;: &#1514;&#1493;&#1488;&#1512; &#1488;&#1497;&#1513; &#1511;&#1513;&#1512; &#1495;&#1493;&#1489;&#1492;">*</asp:RequiredFieldValidator>
                            </span></b></span>
                </td>
                <td style="font-size: 10pt; color: #FFFFFF; background-color: #303F53">
                    <b>מזהה ייחודי</b></td>
            </tr>
            <tr>
                <td style="font-size: 10pt; color: #FFFFFF; font-weight: bold">
                            <span style="font-size: x-small">
                            <font size="2"><span style="font-family: Arial"><b>
                    <span style="color: #FFFFFF">
                            <asp:TextBox ID="TextBox1" runat="server" Width="100%" Height="22px"></asp:TextBox>
                            </span></b></span></font>
                            </span>
                        </td>
                <td style="font-size: 10pt">
                            <span style="font-size: x-small">
                            <asp:TextBox ID="TextBox3" runat="server" Width="100%"></asp:TextBox>
                            </span>
                        </td>
                <td style="font-size: 10pt">
                            <span style="font-size: x-small">
                            <asp:TextBox ID="TextBox2" runat="server" Width="100%"></asp:TextBox>
                            </span>
                        </td>
                <td style="font-size: 10pt">
                    &nbsp;</td>
            </tr>
            <tr>
                <td colspan="4"
                    style="font-size: 10pt; color: #FFFFFF; font-weight: bold; background-color: #303F53">
                    כתובת
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
                                ControlToValidate="TextBox4" ErrorMessage="&#1513;&#1491;&#1492;: &#1499;&#1514;&#1493;&#1489;&#1514; &#1495;&#1493;&#1489;&#1492;">*</asp:RequiredFieldValidator>
                            </td>
            </tr>
            <tr>
                <td colspan="4" style="font-size: 10pt; color: #FFFFFF; font-weight: bold">
                            <span style="font-size: x-small">
                            <asp:TextBox ID="TextBox4" runat="server" Width="100%"></asp:TextBox>
                            </span>
                        </td>
            </tr>
            <tr>
                <td style="font-size: 10pt; color: #FFFFFF; font-weight: bold; background-color: #303F53"
                    width="25%">
                    עיר
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
                                ControlToValidate="TextBox5" ErrorMessage="&#1513;&#1491;&#1492;: &#1506;&#1497;&#1512; &#1495;&#1493;&#1489;&#1492;">*</asp:RequiredFieldValidator>
                </td>
                <td style="font-size: 10pt; color: #FFFFFF; background-color: #303F53"
                    width="25%">
                    <b>מיקוד&nbsp;
                            <span style="font-size: x-small">
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server"
                                ControlToValidate="TextBox6" ErrorMessage="&#1513;&#1491;&#1492;: &#1502;&#1497;&#1511;&#1493;&#1491; &#1495;&#1493;&#1489;&#1492;">*</asp:RequiredFieldValidator>
                            </span>
                            </b>
                </td>
                <td style="font-size: 10pt; background-color: #303F53" width="25%">
                    <span style="color: #FFFFFF"><b>מדינה
                            <span style="font-size: x-small">
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
                                ControlToValidate="TextBox7" ErrorMessage="&#1513;&#1491;&#1492;: &#1502;&#1491;&#1497;&#1504;&#1492; &#1495;&#1493;&#1489;&#1492;">*</asp:RequiredFieldValidator>
                            </span></b></span>
                </td>
                <td style="font-size: 10pt; color: #FFFFFF; background-color: #303F53">
                    <b>אזור</b></td>
            </tr>
            <tr>
                <td style="font-size: 10pt; color: #FFFFFF; font-weight: bold">
                            <span style="font-size: x-small">
                            <asp:TextBox ID="TextBox5" runat="server" Width="100%"></asp:TextBox>
                            </span>
                        </td>
                <td style="font-size: 10pt">
                    <span style="font-size: x-small">
                            <asp:TextBox ID="TextBox6" runat="server" Width="100%"></asp:TextBox>
                            </span>
                        </td>
                <td style="font-size: 10pt">
                            <span style="font-size: x-small">
                            <asp:TextBox ID="TextBox7" runat="server" Width="100%"></asp:TextBox>
                            </span>
                        </td>
                <td style="font-size: 10pt">
                            <span style="font-size: x-small">
                            <asp:TextBox ID="TextBox8" runat="server" Width="100%"></asp:TextBox>
                            </span>
                        </td>
            </tr>
            <tr>
                <td style="font-size: 10pt; color: #FFFFFF; font-weight: bold; background-color: #303F53"
                    width="25%">
                    טלפון<span style="font-size: x-small"><asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
                                ControlToValidate="TextBox9" ErrorMessage="&#1513;&#1491;&#1492;: &#1496;&#1500;&#1508;&#1493;&#1503; &#1495;&#1493;&#1489;&#1492;">*</asp:RequiredFieldValidator>
                            </span>
                </td>
                <td style="font-size: 10pt; color: #FFFFFF; background-color: #303F53; font-weight: bold;"
                    width="25%">
                    <b>פקס</b></td>
                <td style="font-size: 10pt; background-color: #303F53; color: #FFFFFF;"
                    width="25%" colspan="2">
                    <b style="text-align: right">בצע פעולות</b></td>
            </tr>
            <tr>
                <td style="font-size: 10pt; color: #FFFFFF; font-weight: bold">
                            <span style="font-size: x-small">
                            <asp:TextBox ID="TextBox9" runat="server" Width="100%"></asp:TextBox>
                            </span>
                                            </td>
                <td style="font-size: 10pt">
                            <span style="font-size: x-small">
                            <asp:TextBox ID="TextBox10" runat="server" Width="100%"></asp:TextBox>
                            </span>
                                            </td>
                <td style="font-size: 10pt">
                            <span style="font-size: x-small">
                                                                    <asp:Button ID="Button1" runat="server" Text="&#1513;&#1502;&#1493;&#1512;"
                                                                        onclick="Button1_Click" />
                                                                    <asp:Button ID="Button3" runat="server" Text="&#1506;&#1491;&#1499;&#1503;"
                                                                        Visible="False" />
                                                                    <asp:Button ID="Button2" runat="server" Text="&#1504;&#1511;&#1492; &#1496;&#1493;&#1508;&#1505;" />
                            </span>
                                            </td>
                <td style="font-size: 10pt">
                            &nbsp;</td>
            </tr>
            <tr>
                <td style="font-size: 10pt; color: #FFFFFF; font-weight: bold">
                            &nbsp;</td>
                <td style="font-size: 10pt">
                            &nbsp;</td>
                <td style="font-size: 10pt">
                            &nbsp;</td>
                <td style="font-size: 10pt">
                            &nbsp;</td>
            </tr>
            <tr>
                <td style="font-size: 10pt; color: #FFFFFF; font-weight: bold">
                    &nbsp;</td>
                <td style="font-size: 10pt">
                    &nbsp;</td>
                <td style="font-size: 10pt">
                            &nbsp;</td>
                <td style="font-size: 10pt">
                            &nbsp;</td>
            </tr>
            <tr>
                <td style="font-size: 10pt; color: #FFFFFF; font-weight: bold">
                    &nbsp;</td>
                <td style="font-size: 10pt">
                    &nbsp;</td>
                <td style="font-size: 10pt">
                            &nbsp;</td>
                <td style="font-size: 10pt">
                            &nbsp;</td>
            </tr>
        </table>
    </div>
    
</form>

</body>
</html>

0
alex188
8/1/2008 12:37:33 PM

Okay, the immediate answer to your question is to remove, as I said earlier, the single quotes from around the parameter. So this...

Dim sqlstring3 As String = "SELECT * FROM customers WHERE CustomerID= '" & CustomerID & "'"

should become this...

Dim sqlstring3 As String = "SELECT * FROM customers WHERE CustomerID= " & CustomerID

(You may have to change CustomerID to CustomerID.ToString() as well.)

Get that working, then we should tackle the parameterized query issue. You really should be doing it that way, as Mike observed. In reading the other thread, it looks like you weren't getting an exception because you swallowed any exceptions in the catch block without doing anything with them. So make the change I suggest above, then we can help you refine the query.

Don


Don Kiely, MCP, MCSD
In the Last Frontier, Interior Alaska
Please post questions and replies to the forum! And remember to MARK AS ANSWER when someone definitively answers a question or resolves a problem!
0
donkiely
8/1/2008 3:32:20 PM

 what it is mean?

When i  delete TextBox6.Text = reader("postacode").ToString 

It is work ok ! 

postacode 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: postacode

Source Error:

Line 26:             TextBox9.Text = reader("phone").ToString
Line 27: TextBox7.Text = reader("country").ToString
Line 28: TextBox6.Text = reader("postacode").ToString
Line 29: TextBox8.Text = reader("region").ToString
Line 30: TextBox5.Text = reader("city").ToString
0
alex188
8/1/2008 4:50:55 PM

It means that it doesn't find that index in the reader. Do you have it spelled correctly? Should it be "postaLcode", with an L?

Don


Don Kiely, MCP, MCSD
In the Last Frontier, Interior Alaska
Please post questions and replies to the forum! And remember to MARK AS ANSWER when someone definitively answers a question or resolves a problem!
0
donkiely
8/1/2008 6:37:02 PM
 

  Thank you very much.

one more   question i pass customer id from one page to another by QueryString. if a record was selected (by clicking on the SELECT link on gridview) it sent the page: http://website.com/customersPage.aspx?ID=2 on customersPage there is a "check' if a customer was selected:

1    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
2 Dim datakeyvalueinsecondpage As Integer = Request.QueryString("id")
3
4 If datakeyvalueinsecondpage <> 0 Then
5 CustomerID = datakeyvalueinsecondpage
6 datakeyvalueinsecondpage = 0
7 get_data()
8
9 End If
10
11 Label1.Text = datakeyvalueinsecondpage
12 End Sub
13
 
now if the customer was selected. i am looking for the record and select it 
 
1    Protected Sub get_data()
2
3 Button3.Visible = True
4 Button1.Visible = False
5
6 Dim
ConnString1 As String = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|Nwind2003(Good).mdb"
7 Dim sqlstring3 As String = "SELECT * FROM customers WHERE CustomerID= " & CustomerID
8 Dim conn2 As New OleDbConnection(ConnString1)
9 Dim cmd2 As New OleDbCommand(sqlstring3, conn2)
10 cmd2.CommandType = CommandType.Text
11
12 conn2.Open()
13 Dim reader As OleDbDataReader = cmd2.ExecuteReader()
14
15 While reader.Read
16 Label1.Text = reader("ContactName").ToString
17 Label2.Text = reader("Customerid").ToString
18 TextBox10.Text = reader("fax").ToString
19 TextBox9.Text = reader("phone").ToString
20 TextBox7.Text = reader("country").ToString
21 TextBox6.Text = reader("postalcode").ToString
22 TextBox8.Text = reader("region").ToString
23 TextBox5.Text = reader("city").ToString
24 TextBox4.Text = reader("address").ToString
25 TextBox2.Text = reader("ContactTitle").ToString
26 TextBox3.Text = reader("ContactName").ToString
27 TextBox1.Text = reader("CompanyName").ToString
28 End While
29
30 conn2.Close()
31
32
33
34 End Sub
  
 SO FAR IT IS OK, IT FIND THE RECORD BUT I AM NOT ABLE TO UPDATE, i do not sure why, here is my update code
 
1    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs)
2
3 Dim ConnString As String = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|Nwind2003(Good).mdb"
4 Dim sqlstring As String = "Update Customers Set Fax = ?, Phone = ?, Country = ?, Region = ?, City = ?, Address = ?, ContactTitle = ?, CompanyName=? WHERE CustomerID="& CustomerID
5 Dim conn As New OleDbConnection(ConnString)
6 Dim cmd As New OleDbCommand(sqlstring, conn)
7 cmd.CommandType = CommandType.Text
8
9 cmd.Parameters.AddWithValue("fax", TextBox10.Text)
10 cmd.Parameters.AddWithValue("phone", TextBox9.Text)
11 cmd.Parameters.AddWithValue("country", TextBox7.Text)
12 cmd.Parameters.AddWithValue("region", TextBox8.Text)
13 cmd.Parameters.AddWithValue("city", TextBox5.Text)
14 cmd.Parameters.AddWithValue("address", TextBox4.Text)
15 cmd.Parameters.AddWithValue("ContactTitle", TextBox2.Text)
16 cmd.Parameters.AddWithValue("ContactName", TextBox3.Text)
17 cmd.Parameters.AddWithValue("CompanyName", TextBox1.Text)
18
19 conn.Open()
20
21 cmd.ExecuteNonQuery()
22 Response.Write(sqlstring)
23
24 End Sub
  

THE UPDATE CODE IS WORKING, how i am know?

when the QueryString is null, it means no customers was selected. then the user is able to insert a new record.

right after the insert, i am selecting the inserted record, and give an possibility to update the record - then it work ok.

but when i am selecting record by the QueryString it is look like it is an endless loop and the updete not working at all (no errors).
 

0
alex188
8/1/2008 7:52:15 PM
Reply:

Similar Artilces:

System.Data.OleDb.OleDbException: Data type mismatch in criteria expression.
Hi Forum, I have a login script working using text as password, i want to change this to a number, format (000) 000-000, when i submit 025987654 which is formated (025) 987-654 in a field im receiving; Data type mismatch in criteria expression. Any help out there!!! Thanks Paul if the password is truly a number, then you need to drop the quotes from around it when you build the sql statement i.e. select * from tblUser WHERE Password=025987654 and NOT select * from tblUser WHERE Password='025987654' Mike Banavige~~~~~~~~~~~~Need a site code sample in a different language? T...

System.Data.OleDb.OleDbException: Data type mismatch in criteria expression. #2
I am having trouble using OleDb within an ASP.NET application (C#) to write to a Yes/No data field in Access. I have a checkbox on my ASP.NET page and want this to save to a Yes/No field in an Access database. No matter what I try I get a "data type mismatch" message. I've tried the following variations to no avail:1.cmd.Parameters.Add("@SubsidyDoc", this.cbLeaseSubsidy.Checked);2.if (this.cbLeaseSubsidy.Checked == true)      cmd.Parameters.Add("@SubsidyDoc","-1"); else     cmd.Parameters.Add("@SubsidyDo...

System.Data.OleDb.OleDbException was unhandled by user code
Master/Detail Editing - DetailsView I have created a master/detail setup where a GridView displays an complete index to all records in the my database. This in turn links to a DetailsView which gives editing access (New, Update and Delete) to the aforementioned individual records. The first to parts of my application work fine I can add to the access database and update to the access database. However when I attempt to delete from the database i am met with the error 'System.Data.OleDb.OleDbException was unhandled by user code - Data type mismatch in criteria ...

error:An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll
************* Edited by moderator Adec *************** Inserted missing < code></ code> tags. Always include such tags when including code in your postings. Don't force the moderators to do this for you. Many readers disregard postings without the code tags. ************************************************** the error "An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll " occured in the line CONm.open() the code is below: CONM.ConnectionString = "Provider=""MSDAORA.1"";User ...

Data Type Mismatch in criteria Expression, Help~
Error in Explorer: Data type mismatch in criteria expression. Following codings: Dim lowestPrice As Double Dim highestPrice As Double lowestPrice = FormatCurrency(txtLow.Text, 2) highestPrice = FormatCurrency(txtHigh.Text, 2) lblLabel.Text = lowestPrice .. .. "UNION " & _ "SELECT p.ProductID, p.ProductTitle FROM Product p " & _ "WHERE (p.Price > '" & FormatCurrency(lowestPrice, 2) & "' AND p.Price < '" & FormatCurrency(highestPrice, 2) & "') " & _ "ORDER ...

Oledbexception data type mismatch in criteria expression
I am trying to retrieve a number from a query in an access database and am getting the followign error: oledbexception was unhandled by user code data type mismatch in criteria expression  The code is as follows:   Protected Sub GridView2_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles GridView2.SelectedIndexChanged Dim maxDay As String maxDay = "SELECT [MaxofDayNumber] FROM [qryMaxDay] WHERE [entryID]='" & GridView2.SelectedRow.Cells(5).Text & "'" 'maxDay = "SELECT [...

Data type mismatch in criteria expression HELP!!!
Hi, Ive got the following problem, i keep on getting the following error Data type mismatch in criteria expression But when i change the value in the database table to Number and the value of strID to Int it works fine, but when i change the database table to text, and declare strID as a string it gives the message when i click on edit, i dont understand why as if it works for int is should work as string. any help would be greatly appreciated.. the error gives the following line as being responsible for the error Line 43: objDR=Cmd.ExecuteReader(system.data.Command...

Help with error: Data type mismatch in criteria expression
I have the following as part of a class I created to write and read to various .mdbs used at the school where I work:<code>    Function WriteDiscipline(ByVal FacID As String, ByVal HeadID As Long, _                ByVal StuID As String, ByVal DCode As String, _                ByVal InfracDate As Date) As Integer        Dim cmdSQL As New OleDbCommand       ...

Data type mismatch in criteria expression HELP PLEASE
Hi im having a small problem, The problem is when i have my database table feild changed to a string and i declare strID as a string it gives the following error Data type mismatch in criteria expression but when the database table feild is changed to number and strID is declared as integer is works fine, no problems, i cant understand why it wont work when its changed to string, i would leave it as an integer but the rest of the system needs the database table feild to be a string Any help at all as to why it causing this prob...

Help needed / Data type mismatch in criteria expression.
Hi folks, I'm writing a .NET page using VB, attached to an Access database. I've run into the dreaded "Data type mismatch in criteria expression." error. I've reviewed what seems like hundreds of post on the same topic here, and as much as it galls me, I can't seem to figure out where the problem lies. I'm calling a parameterized query when a user selects a value from a listbox. As soon as this happens, I get two data type mismatch errors. 1        Sub lstCategories_SelectedIndexChanged(ByVal s As Object, ByVal e As EventArgs) Ha...

System.Data.OleDb.OleDbException: The DataType do not match in the criteria expression.
Hi I have a little code that get the data from a db the select code line works in VS2005 i can make a debug and it return the number 1, so thats ok, but after the select lineDBAdapter3.Fill(DBDataSet3, "KennelEnggaardText") I get this error:System.Data.OleDb.OleDbException: The DataType do not match in the criteria expression. I want to take the record ID 1's text and place it in a FormView code. Can someone plz. help me.My code is: 1 Private Sub OpenDB3() 2 ' Connection yil en database samt SQL Select forspørgsel 3 DBConnection3 = New OleDbConnection(C...

Help im geting error Data type mismatch in criteria expression.
   Help im geting error Data type mismatch in criteria expression. How ca i get this to work ==========================================================================Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click AccessDataSource1.UpdateCommand = "UPDATE `myguestbook` SET `author` = ?, `subject` = ?, `comments` = ? WHERE `PrimaryKey` = ?"Dim author As New ControlParameter("author", "TextBox1", "Text") AccessDataSource1.UpdateParameters.Add(author)Dim subject As New ControlParamet...

Data type mismatch in criteria expression error when using a DetailsView control in VWD2005 on access DB
I have a Yes/No field in an Access 2000 db that im using to show a simple yes/no checkbox on a web form in VWD2005. When I click the insert link, Im getting the error "Data type mismatch in criteria expression". I believe this is because the form is giving ADO.NET true/false instead of yes or no. Is this correct? And how do I make it so Access will accept the input from a checkbox in a detailsview control? Thanks! -Matt Yes you are correct. The check box checked is a boolean value that is 1 if true and 0 if false. You can hardcode the yes/no in the insert command just pu...

The .Net Data SQL Provider (System.Data.SqlClient) requires Microsoft Data Access Components(MDAC) version 2.6 or later.
I am getting error like The .Net Data SQL Provider (System.Data.SqlClient) requires Microsoft Data Access Components(MDAC) version 2.6 or later. i am working with windowsXP. Already in my system i have MDAC 2.7. I donot know why am i getting error like this. anybody help me please...

Web resources about - System.Data.OleDb.OleDbException: Data type mismatch in criteria expression. HELP ME :) - asp.net.access-datasource

Resources last updated: 12/20/2015 6:10:57 AM