Last post Dec 04, 2010 11:30 PM by snatr
Jul 12, 2010 06:39 PM|gsashwin|LINK
I just started learning ASP.Net using visual basic and trying to insert data into the SQL Server database using forms, but facing hiccups.
Here's what i am doing.
I have a form with say 5 fields. Once the user clicks on submit, these fields' data should be inserted into the Sql server tables.
I am using Visual Web Developer and using the same i have dragged a sqldatasource onto my aspx page and also set up the connection. However i do not know what do i have to add in the
aspx.vb page for inserting data into the table. I need this help in VB. I looked it up on internet but could not find many related to VB. All i could find was a code for ADO.Net.
This is how my code looks like
and this is where i believe i need help with. Can anyone please let me know where do i have to use the textbox Id's and also the column names of the database. I am trying to use SQL Statements to insert data.
cmd.Connection = cnn
Please help me. Thanks,
Jul 12, 2010 07:28 PM|sansan|LINK
If you have sqlDatasource, you can configure the insert statement from the table.
Then in your code behind, you can set the default values and say SqlDataSource.Insert() to insert the record.
check this link
you can also assign the insert parameters from your 5 fields in the form
Jul 13, 2010 01:48 PM|DotNet Duke|LINK
hope below code will be helpful for you. It is writted for sqllite database.., You can take it as an example and try for your scenario.
Public Sub insUser(ByVal username As String, ByVal idnumber As Integer, ByVal state As String)
If myConnection.State = ConnectionState.Closed Then
Dim cmd As New SQLiteCommand
cmd = myConnection.CreateCommand
cmd.CommandText = "Insert into Userinfo(Locatorid, Locatorname,LocatorState, StartTime,CheckoutComplete)" & _
"Values(" & idnumber & ",'" & username & "','" & state & "','" & My.Settings.LoginTime & "', 0);"
Dec 04, 2010 11:30 PM|snatr|LINK
I'm pretty much using this approach. But instead I'm using an sqldatasource control.
I've just got to be conserned with security at this point.
visual web Developer 2005 Express - 2008
visual studio web developer express edition 2008
Sql Server 2008 Express
sql 2005 server
MS Sql Server 2000
Viisual Studio 2008
visual studio 2010
"ASP.NET and SQL Server
asp .net 3.5