Home All Groups Group Topic Archive Search About

Trouble displaying info from access db

Author
20 Nov 2006 4:04 PM
GeekyChicky79
Hi Everyone,

I have the project below where I'm pulling out information from 1 table
"Subjects", pulling the Subjects, and SubjectCode. The Subjects are
displaying in the Combo Box just fine, but I can not get the
corresponding Subject Code to display in the Label.

I have 2 Data adapters/dataset,1 for Subjects, and  the other for
SubjectCode, along with a Data View setup.

I'm a newbie on VB.NET. This project is pulling from an Access DB. Is
there anything that I should be looking for, or doing wrong that I'm
not getting the Subject Code to display in the Label?

Any help would be appreciated.


__________________________________
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
        'Fill the List box
        dbSubject.Fill(DsSubject1)
        dbSubjectCode.Fill(DsSubjectCode2)
        DisplayRecordPosition()
    End Sub

    Private Sub cboSubjectName_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cboSubjectName.SelectedIndexChanged
        '  DsSubject1.Clear()
        ' dbSubject.SelectCommand.Parameters("Subjects").Value =
cboSubjectName.Text
        ' dbSubjectCode.Fill(DsSubjectCode2)
    End Sub

    Private Sub lblSubName_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles lblSubName.Click
        DsSubjectCode2.Clear()
        dbSubjectCode.SelectCommand.Parameters("SubjectCode").Value =
lblSubName.Text
        dbSubjectCode.Fill(DsSubjectCode2)

    End Sub
    '*****General Procedures*****
    Private Sub DisplayRecordPosition()
        Dim intRecordCount As Integer
        Dim intRecordPosition As Integer

        intRecordCount = DsSubject1.Tables("Subjects").Rows.Count

        If intRecordCount = 0 Then
            lblSubName.Text = "(No records)"
        Else
            intRecordPosition = Me.BindingContext(DsSubject1,
"Subjects").Position + 1
            lblSubName.Text = "Record: " & intRecordPosition.ToString _
             & " of " & intRecordCount.ToString
        End If
    End Sub
End Class
_____________________________________________________

Author
20 Nov 2006 4:33 PM
Jeff Allan
The first question is, do you need a DataAdapter?  Are you going to update,
insert or delete data?  If so, then yes a DA is the way to go.  If you are
just reading, use a DataReader.  Much faster.

1.> Fill Data Reader & Bind to Drop Down List (SQL Example)
'Populate Drop Down List
Dim coReader As SqlClient.SqlDataReader

'SQL Server Connection Object From Form - You would replace with your Access
Connection object
conSQL.Open()

'SQL Server Command Object From Form - You would replace with an Access
command object
cmdSQL.CommandText = "SELECT Subject, SubjectCode FROM <<TABLE>> ORDER BY
Subject"

coReader = cmdSQL.ExecuteReader()
ddlSubject.DataSource = coReader
ddlSubject.DataTextField = "Subject"
ddlSubject.DataValueField = "SubjectCode"
ddlSubject.DataBind()
coReader.Close()
conSQL.Close()

2.> On SelectedIndexChange of Combo Box, set Label Value
lblSubCode.Text = CTYPE(ddlSubjects.SelectedValue, String)

This will give you a drop down populated with subjects and then when you
select one, the code of that subject will be displayed in the label.

Show quoteHide quote
"GeekyChicky79" <skp62***@aol.com> wrote in message
news:1164038697.667703.78380@j44g2000cwa.googlegroups.com...
> Hi Everyone,
>
> I have the project below where I'm pulling out information from 1 table
> "Subjects", pulling the Subjects, and SubjectCode. The Subjects are
> displaying in the Combo Box just fine, but I can not get the
> corresponding Subject Code to display in the Label.
>
> I have 2 Data adapters/dataset,1 for Subjects, and  the other for
> SubjectCode, along with a Data View setup.
>
> I'm a newbie on VB.NET. This project is pulling from an Access DB. Is
> there anything that I should be looking for, or doing wrong that I'm
> not getting the Subject Code to display in the Label?
>
> Any help would be appreciated.
>
>
> __________________________________
> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>        'Fill the List box
>        dbSubject.Fill(DsSubject1)
>        dbSubjectCode.Fill(DsSubjectCode2)
>        DisplayRecordPosition()
>    End Sub
>
>    Private Sub cboSubjectName_SelectedIndexChanged(ByVal sender As
> System.Object, ByVal e As System.EventArgs) Handles
> cboSubjectName.SelectedIndexChanged
>        '  DsSubject1.Clear()
>        ' dbSubject.SelectCommand.Parameters("Subjects").Value =
> cboSubjectName.Text
>        ' dbSubjectCode.Fill(DsSubjectCode2)
>    End Sub
>
>    Private Sub lblSubName_Click(ByVal sender As System.Object, ByVal e
> As System.EventArgs) Handles lblSubName.Click
>        DsSubjectCode2.Clear()
>        dbSubjectCode.SelectCommand.Parameters("SubjectCode").Value =
> lblSubName.Text
>        dbSubjectCode.Fill(DsSubjectCode2)
>
>    End Sub
>    '*****General Procedures*****
>    Private Sub DisplayRecordPosition()
>        Dim intRecordCount As Integer
>        Dim intRecordPosition As Integer
>
>        intRecordCount = DsSubject1.Tables("Subjects").Rows.Count
>
>        If intRecordCount = 0 Then
>            lblSubName.Text = "(No records)"
>        Else
>            intRecordPosition = Me.BindingContext(DsSubject1,
> "Subjects").Position + 1
>            lblSubName.Text = "Record: " & intRecordPosition.ToString _
>             & " of " & intRecordCount.ToString
>        End If
>    End Sub
> End Class
> _____________________________________________________
>
Author
20 Nov 2006 4:57 PM
GeekyChicky79
Frankly I don't think I do...but then again I'm new at all of this. All
I'm doing is pulling the information from the Access DB.

DB Name: Subjects
Table1: Subject (Drop down box)
Table2: SubjectCode (Listbox)

Just trying to figure out why the Label isn't displaying the
information. All I'm getting is the Record 1 of 12 displaying in that
Label, and not the "SubjectCode"

If you had the program and click on the Combo Box in the Design View,
in the properties window where you have Data Source...it's pulling the
information for the Subject that way. And in the Form1_Load, it
pulls/displays the information only for the Combo Box.

Any thoughts?
Author
20 Nov 2006 7:15 PM
RobinS
Are you talking about a Label control that is on the form?
Where is "Record 1 of 12" showing up? Sounds like the text
in a Binding Navigator. Are you setting that?

Robin S.
-----------------------------
Show quoteHide quote
"GeekyChicky79" <skp62***@aol.com> wrote in message
news:1164041831.398627.169740@e3g2000cwe.googlegroups.com...
> Frankly I don't think I do...but then again I'm new at all of this. All
> I'm doing is pulling the information from the Access DB.
>
> DB Name: Subjects
> Table1: Subject (Drop down box)
> Table2: SubjectCode (Listbox)
>
> Just trying to figure out why the Label isn't displaying the
> information. All I'm getting is the Record 1 of 12 displaying in that
> Label, and not the "SubjectCode"
>
> If you had the program and click on the Combo Box in the Design View,
> in the properties window where you have Data Source...it's pulling the
> information for the Subject that way. And in the Form1_Load, it
> pulls/displays the information only for the Combo Box.
>
> Any thoughts?
>