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.
"GeekyChicky79" <skp62079@aol.comwrote in message
news:1164038697.667703.78380@j44g2000cwa.googlegro ups.com...
Quote:
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").Val ue =
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("SubjectCod e").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
__________________________________________________ ___
>