提交按钮有错误 [英] having an error in the submit button
本文介绍了提交按钮有错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这些是我在提交"按钮中的代码.
但它表明我的连接有错误.有什么问题吗?请帮助我
these are my codes in a submit button.
but it shows that i have an error in my connection. what could be wrong? please help me
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
GridView1.Visible = True
Dim myConn As OleDbConnection
Dim cmd As OleDbCommand
Dim sqlString, takenby, dest, client, car As String
Dim recordno As Integer
Dim dte, exptime As String
recordno = Integer.Parse(TextBox4.Text)
dte = TextBox1.Text
car = ComboBox1.SelectedValue.ToString()
takenby = ComboBox2.SelectedValue.ToString
dest = ComboBox3.SelectedValue.ToString
client = TextBox2.Text
exptime = TextBox3.Text
myConn = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source = |DataDirectory|Database - copy.accdb;")
myConn.Open()
sqlString = "INSERT INTO DETAILED GISTEC CARS(Record No, Date, Car, Taken By, Destination, Client, Expected Time to Return)VALUES('" + recordno + " ','" + dte + "','" + car + "','" + takenby + "','" + dest + "','" + client + "','" + exptime + " ')"
cmd = New OleDbCommand(sqlString, myConn)
cmd.ExecuteNonQuery()
myConn.Close()
推荐答案
请检查以下链接中的连接字符串,这是连接到Access 2007所必需的:
http://www.connectionstrings.com/access-2007 [
Please check the connectionstrings in the following link, which is required for connecting to Access 2007:
http://www.connectionstrings.com/access-2007[^]
嘿,我不明白为什么你不只是传递变量在作为参数?据我所知,您在''''引号之间传递了字符串.这意味着您传入的每个变量都会被当作字符串/varchar/nvarchar输入.因此,例如,如果您的期望值是int/double/decimal/smallint等,则sql将引发错误.因此,您需要将参数设置为所需的任何数据类型类型列.希望对您有所帮助.
Hey I don''t see why you dont just pass your variables in as paramaters?? As far as I can see you are passing in strings in between '''' quotes. This means that every variable you are passing in is being interputed as a string/varchar/nvarchar whatever. So for instance if you have a value that expects an int/double/decimal/smallint ect.. you sql will throw an error. So you need to set the paramaters to whatever datatype type column expects. Hope this helps.
sqlString = "INSERT INTO DETAILED GISTEC CARS(Record No, Date, Car, Taken By, Destination, Client, Expected Time to Return)VALUES('" + recordno + " ','" + dte + "','" + car + "','" + takenby + "','" + dest + "','" + client + "','" + exptime + " ')"
这是我的错误...它说从字符串"INSERT INTO TECHNICAL GISTEC CARS"到类型"Double"的转换无效.
我没有将任何内容转换为double
this is my error....it says Conversion from string "INSERT INTO DETAILED GISTEC CARS" to type ''Double'' is not valid.
i have converted nothing to double
这篇关于提交按钮有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文