0

Here's the problem, i'm trying to determine if the table is empty or not because if it's empty it will process the next transaction.

Code(Transaction)

 Public Sub insCust()
    i = dtgOnGoing.CurrentRow.Index

    If dtgOnGoing.Rows(i).Cells.Item(0).Value = Nothing Then
        Try
            c = DataGridViewCustomer.CurrentRow.Index

            dt = New DataTable
            da = New MySqlDataAdapter("SELECT SUM(jobprice) from custsrv WHERE GROUP BY custName=@custName", sqlCon)
            da.SelectCommand.Parameters.AddWithValue("@custName", DataGridViewCustomer.Item(0, c).Value)
            da.Fill(dt)
            sqlCon.Close()

            total = DataGridViewCustomer.Item(2, c).Value

            sqlCon.Open()
            dt = New DataTable
            da = New MySqlDataAdapter("INSERT INTO billing (`custName`, `totalAmt`) VALUES (@custName,@total)", sqlCon)
            da.SelectCommand.Parameters.AddWithValue("@custName", DataGridViewCustomer.Item(0, c).Value)
            da.SelectCommand.Parameters.AddWithValue("@totalAmt", total)
            da.Fill(dt)
            MessageBox.Show("Payment is proceeded", "XYZ Auto Repair Shop", MessageBoxButtons.OK, MessageBoxIcon.Information)
            sqlCon.Close()

        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    Else
        MessageBox.Show("No Transaction, please try again", "XYZ Auto Repair Shop", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End If

End Sub

The problem is like this: Object reference not set to an instance of an object. If so, how can i determine if its empty or not?

Alastair23
  • 31
  • 9
  • 1
    Have you tried returning a count of records to determine if it's empty or not? – Fletchius May 16 '17 at 11:29
  • No, not yet and i used this condition to display items in the datagridview: i = DataGridViewCustomer.CurrentRow.Index connect_DB() dt = New DataTable da = New MySqlDataAdapter("SELECT jobSrv as 'Service', jobPrice as 'Price' " & "FROM custsrv WHERE custName=@custName AND jobStats='ON-GOING' ", sqlCon) da.SelectCommand.Parameters.AddWithValue("@custName", DataGridViewCustomer.Item(0, i).Value) da.Fill(dt) disconnect_DB() dtgOnGoing.DataSource = dt – Alastair23 May 16 '17 at 11:34

0 Answers0