"t13", TextBox12.Text)
ViewState.Add("t14", TextBox13.Text) Server.Transfer("Req_Form2.aspx")
End Sub
</script>
Req_Form2.aspx
<script
runat =
"server">
Sub Page_load(ByVal s
As Object,
ByVal e As EventArgs)
Dim Cn As OleDbConnection
Dim Cm As OleDbCommand
Cn =
New OleDbConnection("provider = Microsoft.Jet.OleDb.4.0;" & _
"Data source = " & Server.MapPath("App_Data/EDDataBase.mdb"))
Dim tt1, tt2, tt3, tt4, tt5, tt6, tt7, tt8, tt11, tt13, tt14
As String
Dim tt9, tt10
As Integer
Dim tt0 As
Long
Dim tt12 As
Date
tt1 = ViewState.Item("t1")
Please print out the insert statement on the screen and paste here, and run it inside database, not from the web to see what is wrong with your sql statement
Don't forget to click "Mark as Answer" on the post(s) that helped you.
Open you access database, Queries, Create query in design view, Close, on the top left, you will see SQL, select dropdown choose Sql View, and paste your code there, you can run your sql statement there. (access 2003), other version may have little difference.
Don't forget to click "Mark as Answer" on the post(s) that helped you.
Marked as answer by aasb100 on May 28, 2008 09:25 PM
If the first column is an autonumber type, then you shouldn't be inserting anything into that at all. Second, becasue you are trying to concatenate variables into a string to form a dynamic SQL statement, you are always prone to datatype mismatch and other
errors, along with the possibility of SQL injection. For that reason, you should use parameters:
Also, just because a query runs from the Access Query Designer, don't assume it will work from ASP.NET. Most times it will work fine, but occasionally, it won't. That's because as soon as you use the Jet Oledb provider, you are no longer dealing with an
Access database. It has now become a Jet database, and Jet has it's own slightly different SQL.
aasb100
Member
7 Points
36 Posts
Plz Help
May 28, 2008 04:25 PM|LINK
Hi everone,
its my first post here. i'm programming compuer student and i have problem
with my graduation project using ASP.NET based on VB
error message is " Data type mismatch in criteria expression. "
this my code..
Req_Form1.aspx
<script runat = "server">
Sub Click(ByVal s As Object, ByVal e As EventArgs)ViewState.Add(
"t1", TextBox1.Text) ViewState.Add("t2", DropDownList1.SelectedValue & "/" & DropDownList2.SelectedValue & "/" & TextBox2.Text)ViewState.Add(
"t3", DropDownList3.SelectedValue & "/" & DropDownList4.SelectedValue & "/" & TextBox3.Text) ViewState.Add("t4", TextBox4.Text)ViewState.Add(
"t5", TextBox5.Text) ViewState.Add("t6", TextBox6.Text)ViewState.Add(
"t7", TextBox7.Text) ViewState.Add("t8", TextBox8.Text)ViewState.Add(
"t9", TextBox9.Text) ViewState.Add("t10", TextBox10.Text)ViewState.Add(
"t11", TextBox11.Text) ViewState.Add("t12", ToAD(Now, "d/m/yyyy"))ViewState.Add(
"t13", TextBox12.Text) ViewState.Add("t14", TextBox13.Text) Server.Transfer("Req_Form2.aspx") End Sub</script>
Req_Form2.aspx
<script runat = "server"> Sub Page_load(ByVal s As Object, ByVal e As EventArgs) Dim Cn As OleDbConnection Dim Cm As OleDbCommandCn =
New OleDbConnection("provider = Microsoft.Jet.OleDb.4.0;" & _ "Data source = " & Server.MapPath("App_Data/EDDataBase.mdb")) Dim tt1, tt2, tt3, tt4, tt5, tt6, tt7, tt8, tt11, tt13, tt14 As String Dim tt9, tt10 As Integer Dim tt0 As Long Dim tt12 As Date tt1 = ViewState.Item("t1")tt2 = ViewState.Item(
"t2") tt3 = ViewState.Item("t3")tt4 = ViewState.Item(
"t4") tt5 = ViewState.Item("t5")tt6 = ViewState.Item(
"t6") tt7 = ViewState.Item("t7")tt8 = ViewState.Item(
"t8") tt9 = ViewState.Item("t9")tt10 = ViewState.Item(
"t10") tt11 = ViewState.Item("t11")tt12 = ViewState.Item(
"t12") tt13 = ViewState.Item("t13")tt14 = ViewState.Item("t14")Cn.Open()
Cm =
New OleDbCommand("Insert into PublicInfo values(" & tt0 & ",'" & tt1 & "','" & tt2 & "','" & tt3 & _ "','" & tt4 & "','" & tt5 & "','" & tt6 & "','" & tt7 & "','" & tt8 & "'," & tt9 & "," & tt10 & ",'" & _tt11 & "','" & tt12 & "','" & tt13 & "','" & tt14 & "')", Cn)Cm.ExecuteNonQuery()
Cn.Close()
End Sub</script>
* tt0 is null variable to ganerate auto number in access database>> i don't know if this method right.
i'm wating your help.. regards
TonyDong
Contributor
4777 Points
939 Posts
Re: Plz Help
May 28, 2008 04:38 PM|LINK
tt0 = ViewState.Item("t0")
tt9 = ViewState.Item("t9")tt10 = ViewState.Item(
"t10")tt0, tt9, tt10 is not string ,so you need to convert it to the type you declare like
tt0 = CLong(ViewState.Item("t0") )
tt9 = CInt(ViewState.Item("t9") )tt10 = CInt(ViewState.Item(
"t10"))aasb100
Member
7 Points
36 Posts
Re: Plz Help
May 28, 2008 04:49 PM|LINK
first of all, thank you .
tt0 = CLong(ViewState.Item("t0") )
i didn't add viewstate.item("t0")
it's null variable to send it to access DB Auto number field..
but i tried
tt9 = CInt(ViewState.Item("t9") )tt10 = CInt(ViewState.Item(
"t10"))it's not help :(
TonyDong
Contributor
4777 Points
939 Posts
Re: Plz Help
May 28, 2008 04:57 PM|LINK
Please print out the insert statement on the screen and paste here, and run it inside database, not from the web to see what is wrong with your sql statementaasb100
Member
7 Points
36 Posts
Re: Plz Help
May 28, 2008 05:03 PM|LINK
sorry,
but how can i run insert statement from database not from web .. plz don't crash me
TonyDong
Contributor
4777 Points
939 Posts
Re: Plz Help
May 28, 2008 05:11 PM|LINK
Open you access database, Queries, Create query in design view, Close, on the top left, you will see SQL, select dropdown choose Sql View, and paste your code there, you can run your sql statement there. (access 2003), other version may have little difference.aasb100
Member
7 Points
36 Posts
Re: Plz Help
May 28, 2008 05:38 PM|LINK
hi again,
i used view and query design.. i didn't understand it but it worked
now , what the point from this ?
TonyDong
Contributor
4777 Points
939 Posts
Re: Plz Help
May 28, 2008 06:01 PM|LINK
It means that your sql statement is correct, so you need to focus on the database connection, command etc.
Is it works for other sql statement like update, delete ?
Mikesdotnett...
All-Star
154927 Points
19867 Posts
Moderator
MVP
Re: Plz Help
May 28, 2008 07:21 PM|LINK
If the first column is an autonumber type, then you shouldn't be inserting anything into that at all. Second, becasue you are trying to concatenate variables into a string to form a dynamic SQL statement, you are always prone to datatype mismatch and other errors, along with the possibility of SQL injection. For that reason, you should use parameters:
http://www.mikesdotnetting.com/Article.aspx?ArticleID=76
http://www.mikesdotnetting.com/Article.aspx?ArticleID=26
Also, just because a query runs from the Access Query Designer, don't assume it will work from ASP.NET. Most times it will work fine, but occasionally, it won't. That's because as soon as you use the Jet Oledb provider, you are no longer dealing with an Access database. It has now become a Jet database, and Jet has it's own slightly different SQL.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
aasb100
Member
7 Points
36 Posts
Re: Plz Help
May 28, 2008 08:05 PM|LINK
toni thanx for yout help..
execuse me mikesdonetting..
in code .. Insert Into Contacts (FirstName, LastName) Values (?,?)" ..
(?,?) it is static ? or it changing with fields count? and without auto number field?
maybe you will see that is stupid question, but this code is see it first time and i wish it helps me