Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
this the code I am using in visual basic 2010 ultimate.
I have also used the following youtube link. It is more or less all the same but I cant seem to find what is causing the error. The error is where is says "grdProperties"

http://www.youtube.com/watch?v=4H2g8H0bqEg[^]

VB
Imports System.Data.OleDb
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        OleDbDataAdapter1.Fill(DataSet11)
    End Sub

    Private Sub LandlordID_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LandlordID.SelectedIndexChanged
        Dim ID, SQLString As String
        Dim dtProperties As New DataTable()
        Dim dbDataAdapter As OleDbDataAdapter
        Dim ConnectString As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & "Data Source = Database.accdb"
        ID = LandlordID.Text
        SQLString = "Select * From Properties WHERE ID = " & "'" & ID & "'" & ""
        dbDataAdapter = New OleDbDataAdapter(SQLString, ConnectString)
        grdProperties.DataSource = dtProperties
    End Sub

    Private Sub postcodes_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles postcodes.SelectedIndexChanged
        Dim postcode, SQLString As String
        Dim dtProperties As New DataTable()
        Dim dbDataAdapter As OleDbDataAdapter
        Dim ConnectString As String = "Provider = Microsoft.Jet.OLEDB.4.0;" & "Data Source = Database.accdb"
        postcode = postcodes.Text
        SQLString = "Select * From Properties WHERE postcode = " & postcode & ""
        dbDataAdapter = New OleDbDataAdapter(SQLString, ConnectString)
        dbDataAdapter.Fill(dtProperties)
        grdProperties.DataSource = dtProperties
    End Sub
End Class
Posted
Updated 5-Apr-13 4:32am
v2

1 solution

Check the name of your control (I assume it's a DataGridView?) in the designer - it isn't called grdProperties! If it is, then it would be both declared and accessible within the form. Did you add it to the wrong form?
 
Share this answer
 
Comments
suhail19 5-Apr-13 10:45am    
I just followed exactly as the youtube link and I am not sure. This is also the first time I have used visual basic. What do you mean by "the name of your control"?
OriginalGriff 5-Apr-13 11:02am    
Well, I assume you have a display control to show the data - and you are trying to set it's DataSource property (otherwise it would be pretty pointless you executing the code!)
grdProperties.DataSource = dtProperties
If you haven't added the control called grdProperties to your form in the designer, then the compiler will be unable to find it, and will give you that error message. Did you drag and drop a DataGridView from the toolbox onto your form?
suhail19 5-Apr-13 11:05am    
HI,
Thanks I have sorted it but I now have a new problem. I need to filter data by landlord ID but when I click the landlord ID numbers, the grid just goes blank.
OriginalGriff 5-Apr-13 11:13am    
:laugh:
That's a different problem and needs a new question - and rather more detail than that...what kind of control you are using, what code you are using, and so forth.
suhail19 5-Apr-13 11:26am    
made a new question called filter data/won't let me filter

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900