troubleshooting Question

Update 2 tables in SQL with one event

Avatar of chrisryhal
chrisryhal asked on
Visual Basic.NET
6 Comments1 Solution212 ViewsLast Modified:
Ok, well I had this same question open just the other day, and I was able with help from people on here to get my update to work, but my insert isn't working now.  Below is the code.  No errors, just doesn't insert anything into my TL_Events but it does update TL_Tooling.



Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        '\\\\\\\\\\\\\\\\\SQL CONNECTION TO INSERT TO TL_EVENTS\\\\\\\\\\

        'build sql connection string at run time

        Dim connect As SqlConnection = New SqlConnection()
        connect.ConnectionString = "Data Source=(local);" & _
                                    "Initial Catalog=Triumph;" & _
                                    "Integrated Security=SSPI"



        'Opens the SQL Connection
        connect.Open()

        Dim strSQLInsert As String


        strSQLInsert = "Insert into TL_EVENTS(EventType,Company,EntryDate,EntryPerson,ToolID,Comments) values ("
        strSQLInsert = strSQLInsert & "'" & Trim(txtRedTag.Text) & "',"
        strSQLInsert = strSQLInsert & "'" & Trim(txtCompany.Text) & "',"
        strSQLInsert = strSQLInsert & "'" & Trim(txtEntryDate.Text) & "',"
        strSQLInsert = strSQLInsert & "'" & Trim(txtSupervisor.Text) & "',"
        strSQLInsert = strSQLInsert & "'" & Trim(txtToolID.Text) & "',"
        strSQLInsert = strSQLInsert & "'" & Trim(txtDamageDescription.Text) & "')"

        strSQLInsert = "Update TL_Tooling "
        strSQLInsert = strSQLInsert & " SET StatusCode = '" & Trim(txtRedTag.Text) & "',"
        strSQLInsert = strSQLInsert & " Company = '" & Trim(txtCompany.Text) & "'"
        strSQLInsert = strSQLInsert & " WHERE ToolID = '" & Trim(txtToolID.Text) & "'"





        'open command object(takes two parameters sqlstring, connection)
        Dim command As New SqlCommand(strSQLInsert, connect)

        Try

            'execute command object
            command.ExecuteNonQuery()

        Catch ae As SqlException

            MessageBox.Show(ae.Message)

        Finally

            'clean up code
            command.Dispose()
            connect.Close()
            connect = Nothing

        End Try
ASKER CERTIFIED SOLUTION
Mani Pazhana
Business Analyst

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros