Join 137,271 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,462 people online right now. Registration is fast and FREE... Join Now!
hey people, if anyone feels they can assist me with my query please contact me as soon as possible
i have a simple query, i have data sent to another form, and then the data values sent to the other form are then saved to one of my database tables. the first connection to the first table works fine, however i need to send the remaining data to the remaining 2 tables.
here is the code that seems to be working fine when connected to one table
hope this helps thankyou
CODE
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
'Create Connection for customer table'
Dim Conn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Sahir Osman\My Documents\Business I.T Year 2\test\executivetravel.mdb")
Their isnt another code. i need to know how i can allow the remaining data on my page to be sent to the remaining tables by one save button.
so for e.g the code provided above will save to the Customer table with the values from the lables on the current page, however i have more lables with data for the remaining tables for e.g activity table. how would i start my next connection string, or would it be included in the same connection string?
for e.g. insert into customer values lblfirstname.text i want a new connection to the activity table e.g. insert into activity values lbltennis.text but dont know how to do that using the save button aswell, because the save button will execute that command
hi could you please send me an example of how i would implement this. because i seem to be having difficulties doing so. very grateful for your moral support people
For some reason the Dim command new line has an error, and also the attributes have been named after the attributes in my tables i have already checked this through. can someone please see why this aint working. ive bee trying for ages thankyou for all you help so far people. :-) p.s i have made the relevant changes
CODE
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click 'Create Connection for customer table' Dim Conn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Sahir Osman\My Documents\Business I.T Year 2\test\executivetravel.mdb") Conn.Open() Dim Command As New System.Data.OleDb.OleDbCommand("insert into Customer(firstname, surname, dateofbirth, telephone, email, passportno )values('" & lblfirstname.Text & "', '" & lblsurname.Text & "', '" & lblDOB.Text & "', " & lblcontact.Text & ", '" & lblemail.Text & "', " & lblpassport.Text & " )", Conn) Command.ExecuteNonQuery() Dim Command As New System.Data.OleDb.OleDbCommand("insert into Booking(Adults, Youths, Childs, airport, traveldate, destination, holidaytotal )values(" & lbladult.Text & ", " & lblyouth.Text & ", " & lblinfant.Text & ", '" & lblairport.Text & "', '" & lbldepart.Text & "', '" & lbldestination.Text & "', " & lblbill.Text & " )", Conn) Command.ExecuteNonQuery() Conn.Close() End Sub
First of all please do not make multiple posts with the same question. You only need to post your question once. We have a lot of members with a lot of questions, so be patient.
Please use [ code] tags as indicated in the forum rules to make your posted code more readable.
Since you never answered my question about what are the column attributes for your database. I am going to leave that problem for later, but your SQL statements have some issues.
The reason you are getting the error is you cannot declare an object twice with the same name using a DIM statement. You have already created the object, all you need to do is assign the new SQL statement to it. There are methods available for you to do this.
hi there, sorry for any inconvinience. my attributes for the columns can be viewed here, they are the same as the connection string. i tried to test my system using your innovated code, however to my dsitress it still seems to have constraints executing the code and gives me an error on the first execution line. here is the code, hope you can help me.
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click 'Create Connection for customer table' Dim Conn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Sahir Osman\My Documents\Business I.T Year 2\test\executivetravel.mdb") Conn.Open() Dim Command As New System.Data.OleDb.OleDbCommand("insert into Customer(firstname, surname, dateofbirth, telephone, email, passportno )values('" & lblfirstname.Text & "', '" & lblsurname.Text & "', '" & lblDOB.Text & "', " & lblcontact.Text & ", '" & lblemail.Text & "', " & lblpassport.Text & " )", Conn) Command.ExecuteNonQuery()
hi there sorry would just like to add, [the Command.ExecuteNonQuery()] on the first line shows a data mismatch error on the code. the attributes can be seen in the connection strings. thankyou