I know there have been articles on here under this title but I cannot relate them to my error. I am trying to cobble together a mock query page as part of an assignment for Uni and stumbled upon this script that I have modded to suit. There are two forms, one that runs a set query to a datagrid - this works but on another page script below there is this NullReferenceException
. The code is exactly the same as the working form so what's wrong ?
Public Class Adding_Information
'Dim SQL As New SQLControl
Private SQL As New SQLControl
Public Property DGV_SetQueries As Object
Private Sub btnCustomerFind_Click(sender As Object, e As EventArgs) Handles btnCustomerFind.Click
If txtCustomerName.Text <> "" Then
If SQL.HasConnection = True Then
Dim dgv_QueryData As Object = Nothing
dgv_QueryData.DataSource = SQL.SQLDataset.Tables(0)
'Create a query variable
Dim query As String = "Select
Customer.Title,
Customer.Firstname,
Customer.Surname,
Customer.Email,
Customer.MobileNo,
Customer.Postcode,
Customer.Regno
From
Customer
Where
Customer.Surname = 'Fletcher'
Order By
Customer.Firstname"
SQL.RunQuery(query)
If SQL.SQLDataset.Tables.Count > 0 Then
'ensure that there is only one table
DataGridView1.DataSource = SQL.SQLDataset.Tables(0)
End If
End If
End If
End Sub
Private Sub DGV_SetQueries_CellContentClick(sender As Object, e As DataGridViewCellEventArgs)
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
End Sub
End Class
The DataGridView
is called datagridview1
and hasconnection
is a connection check to the SQL server. Has anyone spotted anything?
Dim dgv_QueryData As Object = Nothing
>>>> dgv_QueryData.DataSource = SQL.SQLDataset.Tables(0)
'Create a query variable
Dim query As String = "Select
The sqlcontrol is a class form that has the functions has connection and – Andrew Bowles Apr 15 '16 at 19:20