Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VS2010
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[^]
 
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 5-Apr-13 4:27am
Edited 5-Apr-13 4:32am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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?
  Permalink  
Comments
suhail19 at 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 at 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 at 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 at 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 at 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)



Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 5 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100