Simple VB.Net DB Question: Simple INSERT into DB from Form

Ok, here is what I think is probably another easy DB/VB.Net 2005 question.

I have a form that has 2 textbox's (textbox1 and textbox2).  I want to input the information typed into these textbox's into a SQL DB.  I have done the following for my code (buiding on what I learned on may last post yesterday:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim str As String
        Const dbct As String = "Data Source=fakedbname;Initial Catalog=fakedb;Integrated Security=SSPI;"
        Dim cn As SqlClient.SqlConnection ' Usually would be in the Function, but it's alone here.
        Dim str2 As SqlClient.SqlCommand 'The actual SQL Command object.
        Dim cnn As New SqlClient.SqlConnection 'The SQL CONNECITON.  THIS IS NEW TO YOU.
        namevar = TextBox1.Text
        datevar = TextBox2.Text
        str = "insert inv(ComputerName, datescanned) values ('" & namevar & "','" & datevar & "')"
        Try
            cn = New System.Data.SqlClient.SqlConnection(dbct) ' Make the conneciton.
            cn.Open() 'Open
            str2 = New SqlClient.SqlCommand ' Not sure why I need to do this twice.
            str2.CommandText = str 'Making the string.
            str2.Connection = cn 'Making the connection.  
            MsgBox(str2.CommandText)
           (********This is where I am assuming the INSERT Command will occur********(
        Catch ex As Exception
            MsgBox("ERRROR")
        End Try
    End Sub

Would I use a DATAWRITER or some other "function" to enter the data.  I'm a VB6 person and in the past I would just use the ADODB.RECORDSET and run the insert.  I'm trying to figure out how to do this now in VB.Net 2005.

Again, this is probably a pretty easy solution, but I'm willing to give 500 points for a good/quick answer.

Thanks everyone.

Chris, Baltimore
clebo99Asked:
Who is Participating?
 
SethiCommented:
str2.ExecuteNonQuery
0
 
SethiCommented:
ExecuteNonQuery method is similar to Execute method that we had in a connection and command object in ADO.
0
 
clebo99Author Commented:
Guys, that worked like a charm...I knew it was something easy like that......I'm going to assume that Update/Delete and any other SQL commands are the same.

Thanks again!!!!

Chris
0
 
SethiCommented:
Both the guys are same :-))

Yes, for update and delete also you use the same method.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.