Pass Parameters

choudhmh

Member
Joined
Jul 18, 2006
Messages
12
Programming Experience
Beginner
Hi,
I have two forms; in one form i'm inserting some fields into a database. When i click the insert button, it inserts the data from the textbox to the database field and redirects me to form two.
In form two i'm trying to retrive the data i've just inserted. I also need to retrive the ID field value which has been generated (AutoNumber) in the database when i inserted the new record.
I'm doing a school project and a bit stuck - can anyone provide me with a sniplet of what code or any advice that would be required to retrive the data from form one to form two.

Thanks

This is my code on form one:

Dim Connection As OleDb.OleDbConnection

Dim MySQL As String = "Insert into CustomerInfo (Name,Address,Postcode,Tel,Mob) values (@Name, @Address, @Postcode, @Tel, @Mob)"

Connection = New OleDb.OleDbConnection("Provider=Microsoft.ACE.Oledb.12.0;Data Source= C:\Inetpub\Test\Testing.accdb; Persist Security Info=False")




Dim Cmd As New OleDb.OleDbCommand(MySQL, Connection)
Cmd.Parameters.Add(New OleDb.OleDbParameter("@Name", TextBox1.Text))
Cmd.Parameters.Add(New OleDb.OleDbParameter("@Address", TextBox2.Text))
Cmd.Parameters.Add(New OleDb.OleDbParameter("@Postcode", TextBox3.Text))
Cmd.Parameters.Add(New OleDb.OleDbParameter("@Tel", TextBox4.Text))
Cmd.Parameters.Add(New OleDb.OleDbParameter("@Mob", TextBox5.Text))

Connection.Open()
Cmd.ExecuteNonQuery()
Connection.Close()

Response.Redirect("Default2.aspx")
 
Last edited:
Back
Top