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) Handles lstCategories.SelectedIndexChanged
2            Dim oConn As New OleDbConnection(ConfigurationManager.AppSettings("ConnectionString"))
3            Dim strSQL2 As String = "SELECT Suggestions.SuggestionID, Categories.CategoryName, Suggestions.Suggestion, Suggestions.Reason, Suggestions.URL, Suggestions.Priority FROM (Categories INNER JOIN Suggestions ON Categories.CategoryID = Suggestions.CategoryID) WHERE Categories.CategoryID = ? AND Suggestions.SuggestionID = (SELECT min(Suggestions.SuggestionID) FROM Suggestions WHERE SuggestionID NOT IN (SELECT SuggestionID FROM Votes WHERE (IP = ?)))"
4            Dim cmdCategory As OleDbCommand = New OleDbCommand(strSQL2, oConn)
5            cmdCategory.Parameters.AddWithValue("CategoryID", lstCategories.SelectedValue)
6            cmdCategory.Parameters.AddWithValue("IP", Request.UserHostAddress.ToString())
7            Try
8                oConn.Open()
9                Dim dtrCategory As OleDbDataReader = cmdCategory.ExecuteReader()
10               dtrCategory.Close()
11               dtrCategory.Dispose()
12               cmdCategory.Dispose()
13               oConn.Close()
14           Catch ex As Exception
15               Response.Write(ex.Message.ToString())
16               Response.Write("<br>lstCategories.SelectedValue=")
17               Response.Write(lstCategories.SelectedValue)
18               Response.Write("<br>Request.UserHostAddress=")
19               Response.Write(Request.UserHostAddress)
20               Response.Write("<br>strSQL2:")
21               Response.Write(strSQL2)
22               Response.Write("<br>")
23           Finally
24               OleDbConnection.ReleaseObjectPool()
25           End Try

I suspect that the errors pertain to lines 5 and 6 of the code, but I just can't seem to figure it out. CategoryID is a number in the database, and IP is text. I tried replacing one line 6 with this line:

cmdCategory.Parameters.AddWithValue("IP", "127.0.0.1")

But, the results were the same. Any thoughts?

Thanks very much,

Steve

    
 
0
sbattisti345
8/20/2007 5:01:37 PM
asp.net.access-datasource 4679 articles. 0 followers. Follow

5 Replies
616 Views

Similar Articles

[PageSpeed] 48

Use like this. This might help you

 

        cmdCategory.Parameters.Add("CategoryID", OleDbType.BigInt).Value = lstCategories.SelectedValue
        cmdCategory.Parameters.Add("IP", OleDbType.VarChar).Value = Request.UserHostAddress.ToString()


Raghu
(MCSD.NET, MCAD.NET, MCDBA)
[Don't forget to click on Mark as answer on the post that helped you ]
0
rmaiya
8/20/2007 5:20:27 PM

Try somthing like this:

Settin gthe dataType of your parameters.

Sub Go()

Dim cmd As OleDbCommand = New OleDbCommand()

cmd.Parameters.Add("CategoryID", OleDbType.Integer)

cmd.Parameters("CategoryID").Value = 1

cmd.Parameters.Add("IP", OleDbType.VarChar)

cmd.Parameters("IP").Value = "10.1.1.15"

End Sub


James Hearst
.NET Application Developer
0
bluemistonline
8/20/2007 5:31:39 PM

rmaiya:

Use like this. This might help you

 

        cmdCategory.Parameters.Add("CategoryID", OleDbType.BigInt).Value = lstCategories.SelectedValue
        cmdCategory.Parameters.Add("IP", OleDbType.VarChar).Value = Request.UserHostAddress.ToString()

Rmaiya,

I gave this a try, but unfortunately the results are identical... :(

0
sbattisti345
8/20/2007 5:39:44 PM

bluemistonline:

Try somthing like this:

Settin gthe dataType of your parameters.

Sub Go()

Dim cmd As OleDbCommand = New OleDbCommand()

cmd.Parameters.Add("CategoryID", OleDbType.Integer)

cmd.Parameters("CategoryID").Value = 1

cmd.Parameters.Add("IP", OleDbType.VarChar)

cmd.Parameters("IP").Value = "10.1.1.15"

End Sub

 

This does the same - no change. :( There's something definitely going wrong here...

I think I'm going to take out the parameters entirely and see if I can get it to work!

0
sbattisti345
8/20/2007 5:42:28 PM

OK, I think I have resolved the issue, although I'm not quite sure. I believe I had a problem with my SQL query. In addition, I wasn't actually binding the results to the gridview.

So, thanks very much for the help! :)

 Steve

0
sbattisti345
8/20/2007 5:58:46 PM
Reply:

Similar Artilces:

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

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

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

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

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

Data type mismatch in criteria expression.
ERROR ON command.ExecuteNonQuery(); trying to upload image into OLE Object field of an Access database---BEGIN CODE--- public static void AddPhoto(int AlbumID, string Caption, byte[] BytesOriginal) {  using (OleDbConnection connection = new OleDbConnection(ConfigurationManager.ConnectionStrings["Personal"].ConnectionString)) {   using (OleDbCommand command = new OleDbCommand("AddPhoto", connection)) {    command.CommandType = CommandType.StoredProcedure;    command.Parameters.Add(new OleDbParameter("@AlbumID", AlbumID...

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.
       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 - Help needed / Data type mismatch in criteria expression. - asp.net.access-datasource

Closed-form expression - Wikipedia, the free encyclopedia
In mathematics , an expression is said to be a closed-form expression if it can be expressed analytically in terms of a finite number of certain ...

Fighting abuse to protect freedom of expression
We believe that protection from abuse and harassment is a vital part of empowering people to freely express themselves on Twitter. Today, as ...

Campus no longer safe place for freedom of expression says free speech advocate
A group representing free speech in Canada says universities are no longer safe places for free expression, instead shying away from being forums ...

Apple acquires ‘Emotient’ facial expression & emotion detection technology
The Wall Street Journal reports Apple has confirmed it has made an acquisition of artificial intelligence startup Emotient . The cloud-based ...

Duke Student Columnist: America’s First Amendment ‘Obsession’ Is ‘Expression Of White Supremacy’
Duke Student Columnist: America’s First Amendment ‘Obsession’ Is ‘Expression Of White Supremacy’

Disney's FaceDirector changes facial expressions in movies
The new tool out of Disney Research's labs could turn an ing&eacute;nue's semi-decent attempt into a finely nuanced performance. This software ...

Leonardo DiCaprio Reacts to Lady Gaga's Golden Globes Win See His Hilarious Expression!
Leonardo DiCaprio Reacts to Lady Gaga's Golden Globes Win See His Hilarious Expression!

Turkey's YouTube Ban Violated Freedom Of Expression, European Court Rules
A YouTube ban in Turkey that lasted two years has now been ruled a violation of the European Convention on Human Rights. Back in 2008, a Turkish ...

Redbubble, A Profitable Channel For Artistic Expression
There is a growing movement of people who never want to follow a trend. Instead they embrace their own creative self-expression and are just ...

Apple Acquires AI Firm Emotient, Their Tech Can Read Emotion In Facial Expressions
Apple Inc. seems to recognize the fact that studying facial expressions is a very big topic of interest for many technology companies. Which ...

Resources last updated: 1/22/2016 8:16:58 PM