Ha after about a day of googling I realised I would need an INSERT statement. But I am still having abit of trouble making it work.
So hear is my stab at it..
Code:
Imports System.Data.SqlClient
Partial Class Bookings
Inherits System.Web.UI.Page
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
'declare string
Dim strFirstName As String
'Assign textbox value to string variable
strFirstName = txtFirstName.Text
'Create a connection object
Dim sqlConn As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\database.mdf;Integrated Security=True;User Instance=True")
'create a command object
Dim sqlComm As New SqlCommand()
'INSERT statement?
sqlComm.CommandText = "INSERT INTO Clients (FirstName) VALUES (strFirstName);"
sqlComm.CommandType = Data.CommandType.Text
sqlComm.Connection = sqlConn
'Open the connection
sqlConn.Open()
End Sub
End Class
I know that I still need to close the connection but not sure when? Is it directly after I open it?
It would also appear that although I am not getting any errors the information I put into the one textbox isn't being written to the database. As it is just one textbox text at the moment for practice I have allowed nulls in the rest of the table so I don't think thats the problem.
The next dilema I have is that I need to insert different bits of information to different tables. Do I just create different sqlcommands for each different insertion and put them all in the same button click event handler?
And the last problem that I can think of right now is maybe my method for entering child names. Currently I am thinking of having a dropdownlist which the user will use to select the amount of children they want to book in I will then programmatically add in the specified amount of textboxes; ie if a user selects 3 children then 6 textboxes will appear one for each childs first and last name. Is this a good way of doing this or is there a better one?
Again thanks alot for any help in advance you can provide.