Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27206

VS 2008 Error in Writing data Not sure where my problem is.

$
0
0
I'm showing 2 pieces of code the first one works fine. The second one is the exact same code with one additional item added to it. and it does not work.

Code:

Sub SaveData()
        Dim mycommand As OleDbCommand = New OleDb.OleDbCommand("SELECT * FROM tblWorkOrder WHERE WOClosed = False AND DeletedWO = False")
        Dim MYCloseDate As String
        Dim SQLQuery = <sql>        UPDATE tblWorkOrder SET WorkOrderCompletedDate= @WorkOrderCompletedDate,
                                                                Notes = @Notes,
                                                                WorkPerformed = @WorkPerformed,
                                                                CompletedBy = @CompletedBy,
                                                                SanitizedBy = @SanitizedBy,
                                                                WOClosed = @WOClosed,
                                                                </sql>

        MYCloseDate = DateTimePicker1.Value

        mycommand.Connection = con
        ' The Where stament was added because it showed up as text in the <SQL> text

        mycommand.CommandText = SQLQuery.Value & "WHERE WorkOrderId = " & txtWorkOrderID.Text

        con.Open()
        mycommand.Parameters.AddWithValue("@WorkOrderCompletedDate", MYCloseDate)
        mycommand.Parameters.AddWithValue("@Notes", txtNotes.Text)
        mycommand.Parameters.AddWithValue("@WorkPerformed", txtWorkCompleted.Text)
        mycommand.Parameters.AddWithValue("@CompletedBy", cboWorkCompletedBy.Text)
        mycommand.Parameters.AddWithValue("@SanitizedBy", cboMachineSanitizedBy.Text)
        mycommand.Parameters.AddWithValue("@WOClosed", True)
        mycommand.Parameters.AddWithValue("@WorkOrderID", txtWorkOrderID.Text)

        Try
            mycommand.ExecuteNonQuery()
            con.Close()
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
            con.Close()
        End Try
    End Sub

Code:

Sub SaveData()
        Dim mycommand As OleDbCommand = New OleDb.OleDbCommand("SELECT * FROM tblWorkOrder WHERE WOClosed = False AND DeletedWO = False")
        Dim MYCloseDate As String
        Dim SQLQuery = <sql>        UPDATE tblWorkOrder SET WorkOrderCompletedDate= @WorkOrderCompletedDate,
                                                                Notes = @Notes,
                                                                WorkPerformed = @WorkPerformed,
                                                                CompletedBy = @CompletedBy,
                                                                SanitizedBy = @SanitizedBy,
                                                                WOClosed = @WOClosed,
                                                                IsDown = @IsDown
                                                                </sql>

        MYCloseDate = DateTimePicker1.Value

        mycommand.Connection = con
        ' The Where stament was added because it showed up as text in the <SQL> text

        mycommand.CommandText = SQLQuery.Value & "WHERE WorkOrderId = " & txtWorkOrderID.Text

        con.Open()
        mycommand.Parameters.AddWithValue("@WorkOrderCompletedDate", MYCloseDate)
        mycommand.Parameters.AddWithValue("@Notes", txtNotes.Text)
        mycommand.Parameters.AddWithValue("@WorkPerformed", txtWorkCompleted.Text)
        mycommand.Parameters.AddWithValue("@CompletedBy", cboWorkCompletedBy.Text)
        mycommand.Parameters.AddWithValue("@SanitizedBy", cboMachineSanitizedBy.Text)
        mycommand.Parameters.AddWithValue("@WOClosed", True)
        mycommand.Parameters.AddWithValue("@WorkOrderID", txtWorkOrderID.Text)
        mycommand.Parameters.AddWithValue("@IsDown", chkIsDown.Checked)
        Try
            mycommand.ExecuteNonQuery()
            con.Close()
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
            con.Close()
        End Try
    End Sub

Name:  Screenshoot of DB.png
Views: 26
Size:  78.8 KB

I added the line IsDown = @IsDown in the SQL code and mycommand.Parameters.AddWithValue("@IsDown", chkIsDown.Checked) in th
e add with values section.

Thanks
Attached Images
 

Viewing all articles
Browse latest Browse all 27206

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>