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 problem would be great
it sys its this line is causing the problem
Line 43: objDR=Cmd.ExecuteReader(system.data.CommandBehavior.CloseConnection)

this error only occures when the edit button is pressed

<%@ 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 %>" Height="27px" Width="151px"></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 7:55:41 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

4 Replies
615 Views

Similar Articles

[PageSpeed] 12

Someone must be able to help me, Please
0
seanmartina
4/5/2004 10:00:04 PM
Thats because the format to pass parameters to sql using dynamic sql is different for numbers and strings...

for int type (or numeric columns)

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

if the studentid is string then it should be

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 & "' "

strings need to be wrapped around with ' s.

hth

***********************
Dinakar Nethi
Life is short. Enjoy it.
***********************
0
ndinakar
4/6/2004 2:14:24 AM


Hi,
that seems to work ok, no error messages, but now it causes a different problem the text boxes fail to get filled with information from the database once i chose the student no in the listbox, but when i set the values to integer and the database feild to anumber the text boxes get filled.
Thanks for all your help
0
seanmartina
4/6/2004 2:33:10 PM
what is the datatype of the column studentid set to in the db ?
***********************
Dinakar Nethi
Life is short. Enjoy it.
***********************
0
ndinakar
4/6/2004 5:04:24 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 ...

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

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

Web resources about - Data type mismatch in criteria expression HELP PLEASE - asp.net.presentation-controls

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

Carmen Sweet by Natalie Weir for Expressions Dance Company at the Q
Less is more in this powerfully impressive dance show. Carmen Sweet , Expressions Dance Company. Choreography: Natalie Weir. Music: Rodion Shchedrin​, ...

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

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

Expressions of Solidarity for France in Red, White and Blue
ABC News Expressions of Solidarity for France in Red, White and Blue ABC News This photograph made available on Saturday Nov. 14, 2015, shows ...

Resources last updated: 12/9/2015 8:20:05 PM