0
Dim odcell = OutgoingdeliveriesDataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString()

        Using _conn As New MySqlConnection("Server = localhost; Username= root; Password =; Database = forms")
            Using cmd
                With cmd
                    MsgBox("Connection Established")
                    .Connection = _conn
                    .Parameters.Clear()
                    .CommandText = "SELECT FormName, Description FROM FormMaintenance WHERE FormCode = @Code"
                    .Parameters.AddWithValue("@Code", odcell)
                    _conn.Open()
                    Dim dr As MySqlDataReader
                    dr = cmd.ExecuteReader()
                    If dr.Read() Then


                        Using _comm As New MySqlCommand()
                            With _comm
                                .Connection = _conn
                                .CommandText = "UPDATE outgoingdeliveries SET FormName = @iName, Description = @iDesc WHERE FormCode = @iCode"
                                .CommandType = CommandType.Text
                                .Parameters.AddWithValue("@iCode", odcell)
                                .Parameters.AddWithValue("@iName", dr.Item(0).ToString())
                                .Parameters.AddWithValue("@iDesc", dr.Item(1).ToString())
                                dr.Close()
                            End With
                            Try

                                _comm.ExecuteNonQuery()

                            Catch ex As MySqlException
                                MsgBox(ex.Message.ToString())
                            End Try
                        End Using
                    End If

                End With

            End Using
        End Using

my outgoingtable doesnt update ,please help .thank you

2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by Reverend Jim
0

You are displaying the message, "Connection Established" before you even try to open the connection. I suspect you haven't specified the server name correctly. On my machine (using MS SQL) it is "Server=.\SQLEXPRESS;". When I try with either "Server=localhost" or "Server=(localhost)" I don't get the connection. Try this (with a different value for servername)

Dim odcell = OutgoingdeliveriesDataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString()
Dim _conn As New MySqlConnection("Server=.\servername; Username= root; Password =; Database = forms")

With cmd

    _conn.Open()

    If _conn.State = ConnectionState.Open Then

        MsgBox("connection established")

        .Connection = _conn
        .Parameters.Clear()

        .CommandText = "SELECT FormName, Description FROM FormMaintenance WHERE FormCode = @Code"
        .Parameters.AddWithValue("@Code", odcell)

        Dim dr As MySqlDataReader = cmd.ExecuteReader()

        If dr.Read() Then

            Dim _comm As New MySqlCommand()
            With _comm
               .Connection = _conn
               .CommandText = "UPDATE outgoingdeliveries SET FormName = @iName, Description = @iDesc WHERE FormCode = @iCode"
               .CommandType = CommandType.Text
               .Parameters.AddWithValue("@iCode", odcell)
               .Parameters.AddWithValue("@iName", dr.Item(0).ToString())
               .Parameters.AddWithValue("@iDesc", dr.Item(1).ToString())
               dr.Close()
            End With

            Try
                _comm.ExecuteNonQuery()
            Catch ex As MySqlException
                MsgBox(ex.Message.ToString())
            End Try

       End If

   End If

End With

Edited by Reverend Jim

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.