Load from dynamic combo box

pryspr01

Member
Joined
Jan 5, 2006
Messages
15
Programming Experience
Beginner
I see a lot of questions on this, looks to be a hard item. I'm new to vb.net, so I too am having some troubles with this. I have the following so far, but i get a system.nullreferenceexception error. All I want is for the combo box to list a column from the DB, and then if it is selected, to press Load, and it will load the corresponding row values to the textboxes, combo boxes, etc.

VB.NET:
    Private Sub frmprospect_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'OleDbDataAdapter1.Fill(DataSet1, "ProspectTable")
        'cbAutoComplete.DataSource = DataSet1.Tables("ProspectTable")
        'cbAutoComplete.DisplayMember = "FullName"

        Dim conStr As String = "Provider=SQLOLEDB.1;Server=DBV;Database=EnrollmentManagement;Integrated Security=SSPI"
        Dim sqlStr As String = "SELECT * FROM ProspectTable"
        Dim conn As OleDbConnection = New OleDbConnection(conStr)
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(sqlStr, conn)

        Dim ds As DataSet = New DataSet
        da.Fill(ds, "FullName")

        Dim dv As DataView = ds.Tables("ProspectTable").DefaultView
        cbAutoComplete.DataSource = dv
        cbAutoComplete.DisplayMember = "FullName"
        sspanelSearch.Visible = False
    End Sub
 
Hi

Firstly, u r tryin to fill the dataset using the following fill method:

da.fill(ds, "FullName")

Now the table that will be created will refer to the Prospects table in the database and the name of the table in your application will be FullName.

Now u have used the following command to instantiate a dataview

dim dv as dataview=ds.Tables("ProspectsTable").defaultview

But the table named ds.Tables("ProspectsTable") does not exist in the dataset as it is aliased to "FullName" that is why u r gettin nullreference exception. Next u r tryin to set the Display Memmber property to "FullName" which will again show an error.

Try to use the followin:

da.fill(ds, "ProspectsTable")
Rest could be the same
 
Ah i see

Oh ok I understand that now. Makes sense, was totally skipping that in my mind. Maybe you or someone else can advise me on the next step here. I need to take the value FullName, and get all the info from that row in the DB and populate textboxes with it. I found something like this, but no results. (I have this code on the button click event to populate fields)

VB.NET:
        Dim drv As DataRowView = CType(cbAutoComplete.SelectedItem, DataRowView)
        txtLNAME = drv("txtLNAME")
        txtFNAME = drv("txtFNAME")
        txtMNAME = drv("txtMNAME")


Keep gettin an argument exception in system.data.dll in the 2nd line. Can anyone explain this to me?
 
Back
Top