I'm having trouble fill up my DataGridView. I have three bits of code which are underlined blue:
- 'SqlDataAdapter'- It says "Type 'SqlDataAdapter' is not defined"
- 'dgv'- It says "'dgv' is not declared"
- 'SQLCon' - It says "'SQLCon' is not declared"
The code within my form:
Public Class Form4
Dim SQL As New SQLControl
Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load
With DGVData
SQL.SQLDS = Nothing
.Rows.Clear()
.ColumnCount = 3
.Columns(0).HeaderText = "Booking ID"
.Columns(0).Width = 75
.Columns(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(0).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(1).HeaderText = "Payment Confirmation"
.Columns(1).Width = 100
.Columns(1).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(2).HeaderText = "Total Cost"
.Columns(2).Width = 100
.Columns(2).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
End With
LoadBookingData()
End Sub
Private Sub LoadBookingData()
Dim loadSQL As String = "SELECT * FROM booking"
Dim LoadAdapter As New SqlDataAdapter
Dim LoadDataSet As New DataSet
Dim RowsCount As Integer
dgv.Rows.Clear()
If SQLCon.State = ConnectionState.Closed Then
SQLCon.open()
LoadAdapter.fill(LoadDataSet, "GettingInfo").
RowsCount = LoadDataSet.Tables("GettingInfo").Rows.Count
If RowsCount < 1 Then
MsgBox("There is no records", MsgBoxStyle.Critical, "Sorry")
LoadDataSet.Reset()
Con.Close()
Else
' there are records !
dvg.Rows.Add(RowsCount)
For i As Integer = 0 To RowsCount - 1
With dvg
.Rows(1).Cells(0).Value = LoadDataSet.Tables("GettingInfo").Rows(i).Item("bookingID")
.Rows(1).Cells(0).Value = LoadDataSet.Tables("GettingInfo").Rows(i).Item("paymentConfirmation")
.Rows(1).Cells(0).Value = LoadDataSet.Tables("GettingInfo").Rows(i).Item("totalCost")
End With
Next
End If
LoadDataSet.Reset()
Con.Close()
Else
' the connection is already open
LoadAdapter.fill(LoadDataSet, "GettingInfo").
RowsCount = LoadDataSet.Tables("GettingInfo").Rows.Count
If RowsCount < 1 Then
MsgBox("There is no records", MsgBoxStyle.Critical, "Sorry")
LoadDataSet.Reset()
Con.Close()
Else
' there are records !
dvg.Rows.Add(RowsCount)
For i As Integer = 0 To RowsCount - 1
With dvg
.Rows(1).Cells(0).Value = LoadDataSet.Tables("GettingInfo").Rows(i).Item("bookingID")
.Rows(1).Cells(0).Value = LoadDataSet.Tables("GettingInfo").Rows(i).Item("paymentConfirmation")
.Rows(1).Cells(0).Value = LoadDataSet.Tables("GettingInfo").Rows(i).Item("totalCost")
End With
Next
End If
LoadDataSet.Reset()
Con.Close()
End If
End Sub
My 'SQLControl.vb' which i think something has to do with it :
Imports System.Data.SqlClient
Public Class SQLControl
Private SQLCon As New SqlConnection With {.ConnectionString = "Data Source=JENNIFER\DDAP2015;Initial Catalog=zachtravelagency;Integrated Security=True;"}
Private SQLcmd As SqlCommand
Public SQLDA As SqlDataAdapter
Public SQLDS As DataSet
Can someone highlight my errors please?