Click here to Skip to main content
15,924,507 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

VB
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()
Posted
Updated 26-Jun-12 21:30pm
v2
Comments
Sandeep Mewara 27-Jun-12 3:53am    
What error? Putting all the details will just help you getting correct direction.

Please check the connectionstrings in the following link, which is required for connecting to Access 2007:

http://www.connectionstrings.com/access-2007[^]
 
Share this answer
 
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.
 
Share this answer
 
SQL
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 + " ')"


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
 
Share this answer
 
Comments
Om Prakash Pant 27-Jun-12 7:30am    
Can you print "sqlString" and show the output?
Also, convert other variables like dte, takenby used in the query to string (if they are not string variables).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900