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 [balance] FROM [tblEntry] WHERE [entryID]='" & GridView2.SelectedRow.Cells(5).Text & "'"

        Dim DataConn1 As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("App_Data/0715713.mdb"))

        Dim MaxDayCommand As New OleDbCommand(maxDay, DataConn1)
        DataConn1.Open()
        Dim MaxDayReader As OleDbDataReader = MaxDayCommand.ExecuteReader()
        MaxDayReader.Read()

        Response.Redirect("playCompetition.aspx?entryID=" & GridView2.SelectedRow.Cells(5).Text & "&day=" & MaxDayReader("maxDay"))

        MaxDayReader.Close()
        DataConn1.Close()


    End Sub
  
0
controlz
4/14/2009 2:55:28 PM
asp.net.access-datasource 4679 articles. 0 followers. Follow

5 Replies
759 Views

Similar Articles

[PageSpeed] 29

I suspect that EntryID is a Numeric value? If that's the case,  assume that GridView2.SelectedRow.Cells(5) contains the value 5. The maxday will be:

SELECT [MaxofDayNumber] FROM [qryMaxDay] WHERE [entryID]='5'

However, it should be:

SELECT [MaxofDayNumber] FROM [qryMaxDay] WHERE [entryID]=5

You should use the quotes for string values only. To avoid any of this, you better learn yourself to use parameter queries:

  

maxDay = "SELECT [MaxofDayNumber] FROM [qryMaxDay] WHERE [entryID]=?"
Dim DataConn1 As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=|DataDirectory|0715713.mdb"))
Dim MaxDayCommand As New OleDbCommand(maxDay, DataConn1)
MaxDayCommand.Parameters.AddWithValues("", GridView2.SelectedRow.Cells(5).Text)
......
 

http://www.mikesdotnetting.com/Article.aspx?ArticleID=26

Also not that i changed the connectionstring slightly:

http://www.mikesdotnetting.com/Article.aspx?ArticleID=78

0
hans_v
4/14/2009 4:14:29 PM

Oh excellent I didn't spot that :)

 

Problem with coding is now that I have fixed that another error has occured! argh.

 

When I click the button I get the following line "Response.Redirect("playCompetition.aspx?entryID=" & GridView2.SelectedRow.Cells(5).Text & "&day=" & MaxDayReader("maxDay"))"  highlighted with the erro:

IndexOutofRangeException was unhandled by user code
MaxDay

 


0
controlz
4/14/2009 5:00:21 PM

You're retreiving the [MaxofDayNumber] field, not [maxDay]!

0
hans_v
4/14/2009 6:03:06 PM

 Excellent, you have saved my bacon!!

 

Thanks

0
controlz
4/14/2009 6:09:38 PM

I am now getting the error:

System.Data.OleDb.OleDbException: No value given for one or more required parameters.

The query is definately functioning.  Code as follows:

  

1        Protected Sub GridView2_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles GridView2.SelectedIndexChanged
2    
3            Dim maxDay As String
4            maxDay = "SELECT [MaxOfdayNumber], [entryDayID] FROM [qryMaxDay] WHERE [entryID]=" & GridView2.SelectedRow.Cells(5).Text & ""
5    
6            Dim DataConn1 As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("App_Data/0715713.mdb"))
7    
8            Dim MaxDayCommand As New OleDbCommand(maxDay, DataConn1)
9            DataConn1.Open()
10           Dim MaxDayReader As OleDbDataReader = MaxDayCommand.ExecuteReader()
11           MaxDayReader.Read()
12   
13           'Label3.Text = MaxDayReader("MaxOfdayNumber")
14           Response.Redirect("playCompetition.aspx?entryID=" & GridView2.SelectedRow.Cells(5).Text & "&entryDayID=" & MaxDayReader("entryDayID") & "&day=" & MaxDayReader("MaxOfdayNumber"))
15   
16           MaxDayReader.Close()
17           DataConn1.Close()
18   
19   
20       End Sub
 

 

 

0
controlz
4/15/2009 10:39:38 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: Data type mismatch in criteria expression. HELP ME :)
Hellothis is my select code1 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.Text6 Response.Write(sqlstring3)7 8 conn2.Open()9 Dim reader As OleDbDataReader = cmd2.ExecuteRe...

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...

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 ...

Data type mismatch in criteria expression
Hiya. I'm using Access2000 and DBI::ODBC. I'm trying to insert into a table called Volunteers, and I continually get this error: -------------- Died while executing:<br>[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression. (SQL-22005)(DBD: st_execute/SQLExecute err=-1)<hr> at c:\inetpub\wwwroot\EBA\cgi-bin\edit_volunteers.pl line 472. -------------- I don't understand what data type is incorrect though. There are only 2 fields which have a specific criteria: 1) Confirmed: "Yes" or "No 2) Position: maaaany d...

Data type mismatch in criteria expression.
I WILL TRY TO TELL SIMPLE:  an autonumber (long integer) column in MS Access named fakulte_kod a datagrid has templatecolumn with a itemtemplate <asp:label ID="kod" runat="server" Text='<%# Container.DataItem("fakulte_kod") %>'>  and an update routine with these: Dim fakulte_kod_txt As Label = E.Item.FindControl("kod") Dim fakulte_kod_data As String = fakulte_kod_txt.Text Dim db_command As New OleDbCommand("UPDATE fakulteler SET fakulte_ad='"& fakulte_ad_data &"' WHERE fakulte_kod='"& CLng(fakulte_kod_data) &"' ",db_connect) SO WHA...

Data type mismatch in criteria expression
Hi, Im having a small problem, when i change my database table feild to text and declare strID as string i get the following error Data type mismatch in criteria expression but when i change my table feild to Number and declare my StrID as Integer it works no problems, i dont understand when the two values are declared as a String EG strID as String and table feild as text it should work, i would leave it as an integer but the rest of the system requires the StudentID to be a string. Any Help would Be fantastic Dim intWdth as integer Dim strID, strFirst, str...

Data type mismatch in criteria expression.
System.Data.OleDb.OleDbException: Data type mismatch in criteria expression. i'm getting this error while executing my onsert query. I verified all of the types of the values I'm entering and i'm not getting any positive results. Can someone help me out here? the error is generated at the "executenonquery" line Dim connectionString As String = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("..\data\Original_MLBDlicensing.mdb") Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConn...

Data type mismatch in criteria expression
Hi, I'm getting this error "System.Data.OleDb.OleDbException: Data type mismatch in criteria expression" and I don't know how to fix it.  I try it many differently ways and none of them work. I have a formview with insert template.  I'm using Access database.  The table has three column - id, title, users.  The datatype is "text" for both fields.  The problem is the users field.  I want to grab the value form checkboxlist and insert into database but getting the error.  <asp:FormView ID="FormView1" runat="...

Data Type Mismatch in Criteria Expression?!?
Hi All, I'm losing my hair on this one. I've got a form in which I am updating some info in an Access 2000 db. There will be fields that will remain empty which will be filled in at a later time. When date fields, and some number fields, are filled in, I get NO error. However, when I try to run the update when the date fields are empty, I get the following error: 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 o...

Data Type Mismatch in Criteria Expression
hi guys,  I getting this error. Here is my SQL statement, Thinks this may be why im gettin the error. OleDbCommand myCommand = new OleDbCommand("UPDATE patient SET title = '" + title + "', fName = '" + fName + "', sName = '" + sName + "', address1 = '" + address1 + "', address2 = '" + address2 + "', address3 = '" + address3 + "', postcode = '" + postcode + "', contactNumber = '" + contactNumber + "', DOB = '" + DOB + "'...

Data type mismatch in criteria expression.
       Server Error in '/' Application. 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 21: {Line 22: Line 23: this.SqlDataSource1.Insert();Line 24: Line 25: Source File: E:\OrderWebApp\OrderWebApp...

Data type mismatch in criteria expression.
Get this error when tring to run th efollowing code. Function close(ByVal status As String, ByVal dtnow As DateTime) As Integer Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=D:\Documents an"& _ "d Settings\Mathew\My Documents\Auction.mdb" Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString) Dim queryString As String = "UPDATE [Auction] SET [Status]=@Status WHERE ([Auction].[End_Date] <= @dtnow)" ...

Web resources about - Oledbexception data type mismatch in criteria expression - asp.net.access-datasource

Resources last updated: 12/4/2015 10:18:07 PM