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.CommandBehavior.CloseConnection)

heres the code.
<%@ Page Language="vb" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
Dim intWdth as integer
Dim strID, strFirst, strLast, strTitle, strtest as string
Sub Page_Load(Source as Object, E as EventArgs)
strtest="CL2"
if not Page.IsPostBack then
BindData
End If
End Sub

Sub BindData()

Dim strConn as String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= C:\Documents and Settings\sean\Desktop\project\data\StudyAdvisors.mdb"
Dim sql as string = "SELECT Student.StudentID, Student.StudentFirstName, Student.StudentLastName, Student.CourseID, Student.StudyGroupID, Student.Campusid, Student.Comments, Student.Week1, Student.Week2, Student.Week3, Student.Week4, Student.Week5, Student.Week6, Student.Week7, Student.Week8, Student.Week9, Student.Week10, Student.Week11, Student.Week12, Student.Week13, Student.Email FROM Student Where StudygroupID = '" & strtest & "'"
Dim conn as New OleDbConnection(strConn)
Dim Cmd as New OleDbCommand(sql, conn)
Dim objDR as OleDbDataReader
conn.Open()
objDR=Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)
list1.datasource=objDR
list1.DataValueField="StudentID"
list1.datatextfield="StudentID"
list1.databind
list1.selectedindex=0
conn.Close()

End Sub

Sub EditRecord(Source as Object, E as EventArgs)

Dim strConn as String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= C:\Documents and Settings\sean\Desktop\project\data\StudyAdvisors.mdb"
Dim sql as string = "SELECT Student.StudentID, Student.StudentFirstName, Student.StudentLastName, Student.CourseID, Student.StudyGroupID, Student.Campusid, Student.Comments, Student.Week1, Student.Week2, Student.Week3, Student.Week4, Student.Week5, Student.Week6, Student.Week7, Student.Week8, Student.Week9, Student.Week10, Student.Week11, Student.Week12, Student.Week13, Student.Email FROM Student Where [StudentID] = " & List1.selecteditem.value
Dim conn as New OleDbConnection(strConn)
Dim objDR as OleDbDataReader
Dim Cmd as New OleDbCommand(sql, conn)
conn.Open()
objDR=Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)

'response.write(list1.selecteditem.value)

While objDR.Read()
textbox1.text=objDR("StudentID")
frmFirstName.text=objDR("StudentFirstName")
frmLastName.text=objDR("StudentLastName")


End While

objdr.close
conn.close()



End Sub


Sub doUpdate(Source as Object, E as EventArgs)
Dim strConn as String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= C:\Documents and Settings\sean\Desktop\project\data\StudyAdvisors.mdb"
Dim MySQL as string = "Update Student Set StudentID=@StudentID, StudentFirstName=@StudentFirstName, StudentLastName=@StudentLastName Where StudentID=@StudentID"
Dim Conn as New OleDbConnection(strConn)
Dim Cmd as New OleDbCommand(MySQL, Conn)
cmd.Parameters.Add(New OleDbParameter("@StudentID", TextBox1.text))
cmd.Parameters.Add(New OleDbParameter("@StudentFirstName", frmFirstName.text))
cmd.Parameters.Add(New OleDbParameter("@StudentLastName", frmLastName.text))

Conn.Open()
cmd.ExecuteNonQuery
label1.text = "It's Done!"

label1.text="Successfully updated -- - "
BindData
list1.SelectedIndex=List1.Items.IndexOf(List1.Items.FindByValue(TextBox1.text))

End Sub
'
</script>
<html>
<head>
</head>
<body>
<form name="form1" runat="server">
<table width="100%" border="1">
<tbody>
<tr>
<td valign="top" align="middle" width="145">
Choose from List:
<br />
<asp:ListBox id="List1" runat="server" Rows="1"></asp:ListBox>
<br />
<asp:button id="button1" onclick="EditRecord" runat="server" Text="Edit Record"></asp:button>
</td>
<td valign="top" align="left">
ID :
<asp:TextBox id="TextBox1" runat="server" Text="<%# strID %>" ReadOnly="True"></asp:TextBox>
<br />
<br />
FirstName :
<asp:textbox id="frmFirstName" runat="server" Text="<%# strFirst %>"></asp:textbox>
<br />
<br />
LastName :
<asp:textbox id="frmLastName" runat="server" Text="<%# strLast %>" Width="151px" Height="27px"></asp:textbox>
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br />
<br />
<asp:button id="button2" onclick="doupdate" runat="server" Text="Update"></asp:button>
<asp:Label id="label1" runat="server" forecolor="red"></asp:Label>
<br />
<asp:Label id="label2" runat="server"></asp:Label></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
0
seanmartina
4/5/2004 6:25:00 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

7 Replies
548 Views

Similar Articles

[PageSpeed] 46

hello,

in the following line:
StudygroupID = '" & strtest & "'"
do u have the StudygroupID as a text or integer ? if it an integer then what u have been doing is wrong else its right
if the id was an integer:
"StudygroupID = " & strTest
good luck.
Bilal Hadiar, MCP, MCTS, MCPD, MCT
Microsoft MVP - Telerik MVP
0
haidar_bilal
4/5/2004 8:25:31 PM
Hi, thanks for getting back to me, 

the following line StudygroupID = '" & strtest & "'" thats just a bit of code for testing as im going to be redirecting from a search page and thats what will hold the value passed from the search page, it has no bearing on the actuall function of the page,
StudygroupID is a string, all values in the database is string, as ill be using valadition through asp
0
seanmartina
4/5/2004 9:08:43 PM
Hi, have u tried to inlcude

strtest inside the if statement that u have ?
Sub Page_Load(Source as Object, E as EventArgs)
if not Page.IsPostBack then
strtest="CL2"
BindData
End If
End Sub
try this and please do reply to me, sorry for this, but i am unable to know what is exatly happening so i am trying possible solutions !!!
Bilal Hadiar, MCP, MCTS, MCPD, MCT
Microsoft MVP - Telerik MVP
0
haidar_bilal
4/5/2004 9:35:28 PM

Hi maybe ill try and reexplain what is happening,

In this line of code,
Dim strID, strFirst, strLast, strTitle, strtest as string
StrID to an integer and then change the Database feild StudentID to textValue then i get the error message
But if i change strID to an integer thne change the Database Field StudentID to a accept value number(i change this value through the actuall access database) then it works fine no problems,
What i want is to declare StrID as a String and change the database table Field StudentID to value Text
it works fine until i press the edit button then error message.
what is supposed to happen is when i click on the studentID no in the list box, the text boxes fill with the studentID values IE, first name lastname and studentID ready for editing.

the Values you talk about
*************************************
strtest="CL2"
This is just test data as ill be redirecting from a search test, and this has nothing to do with the application, its just to test the search page, the application does not need this piece of code to function
***************************************************************
0
seanmartina
4/5/2004 9:58:55 PM
hello,

u said that StudentId should be a text right ? u can do this inside Ms ACcess and not in ur code !!!! go to the table and change its type, this is one.
Sub EditRecord(Source as Object, E as EventArgs)
Dim strConn as String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= C:\Documents and Settings\sean\Desktop\project\data\StudyAdvisors.mdb"
Dim sql as string = "SELECT Student.StudentID, Student.StudentFirstName, Student.StudentLastName, Student.CourseID, Student.StudyGroupID, Student.Campusid, Student.Comments, Student.Week1, Student.Week2, Student.Week3, Student.Week4, Student.Week5, Student.Week6, Student.Week7, Student.Week8, Student.Week9, Student.Week10, Student.Week11, Student.Week12, Student.Week13, Student.Email FROM Student Where [StudentID] = " & List1.selecteditem.value
Dim conn as New OleDbConnection(strConn)
instead of that big sentence above use this:
Sub EditRecord(Source as Object, E as EventArgs)
Dim strConn as String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= C:\Documents and Settings\sean\Desktop\project\data\StudyAdvisors.mdb"
Dim sql as string = "SELECT * FROM Student Where StudentID = '" & List1.selecteditem.value & "'"
Dim conn as New OleDbConnection(strConn)
try tis and tell me what happens
Bilal Hadiar, MCP, MCTS, MCPD, MCT
Microsoft MVP - Telerik MVP
0
haidar_bilal
4/6/2004 9:12:21 AM
Hi Fantastic, works a treat i think the problem was i had not got the original enclosed in ' ' as i learned that string values need to be enclosed 

thanks for everything, and greatly apreciated
0
seanmartina
4/6/2004 2:50:04 PM
i am glad i was able to help you out, best of luck.
Bilal Hadiar, MCP, MCTS, MCPD, MCT
Microsoft MVP - Telerik MVP
0
haidar_bilal
4/6/2004 3:34:49 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~
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 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...

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

Form View "Data type mismatch in criteria expression."
 I'm not sure what this error means, but here's what the error says: Data type mismatch in criteria expression. body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px} b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px} H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red } H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maro...

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

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

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

Web resources about - Data type mismatch in criteria expression HELP!!! - asp.net.web-forms

Expression (sign language) - Wikipedia, the free encyclopedia
Signs with two different expressions. The pursed lips and partly closed eyes on the left, and raised lip on the right, are necessary for proper ...

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

Joe Rogan's Facial Expression After Ronda Rousey Got Knocked Out Was Priceless - Bleacher Report
Joe Rogan 's face spoke for us all Saturday night. After UFC superstar Ronda Rousey got knocked out by a lethal kick from Holly Holm, the commentator ...

Jack Dorsey: 'Twitter stands for freedom of expression'
Newly-instated CEO Jack Dorsey laid out Twitter's commitment to open dialogue, in a keynote on stage at today's Twitter Flight developer conference ...

Make your technology a force for musical expression with this digital guitar
Computers, tablets, even iPhones have grown into powerful tools for music making, but for many who play guitar the bridge from analog instrument ...

Computers learn how to spot hidden facial expressions
Machines are good at spotting obvious emotions like smiles, but they're not so hot at detecting the extremely brief microexpressions that reveal ...

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

Smile!: Impressive Real-Time Facial Expression Transfer
This is a video from Stanford University of a system developed to transfer one person's facial expressions in real time to a live video feed ...

How Facial Recognition Uses Super-Simple Patterns to Understand Your Expression
Facial recognition systems use all kinds of clever software to work out who you are and even how you’re feeling. But in this video explainer, ...

Resources last updated: 12/29/2015 10:02:47 PM