I've been working on this project which requires me to insert data into a database. Due to the complexities of the function that I am doing, it is more complex to use SqlDataSource and hence I've used the traditional method of inserting to the database.
The codes are as follows:
Private Sub reviewFV_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles reviewFV.ItemInserting
Dim textboxcomment As TextBox = reviewFV.FindControl("commentTB")
Dim comments As String = textboxcomment.Text
Dim reviewId As String = generateReviewID()
'get connection string from web.config
Dim strConn As String = ConfigurationManager.ConnectionStrings("ProrsumDBConnectionString").ConnectionString
'create sql connection
Dim myConn As New SqlConnection(strConn)
'Open connection; Note: You need to open a connection to database
Dim cmd As String = "INSERT INTO Review(reviewID, comments, reviewDate, custID, sessionID, tourID) VALUES (@reviewID, @comments, @reviewDate, @custId, @sessId, @tourId)"
Dim myCmd As New SqlCommand(cmd, myConn)
Dim tid As String = Session("tid")
Dim sid As String
View Complete Post