473,386 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Trouble displaying info from access db

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
__________________________________________________ ___

Nov 20 '06 #1
3 1148
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" <sk******@aol.comwrote in message
news:11*********************@j44g2000cwa.googlegro ups.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").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
__________________________________________________ ___

Nov 20 '06 #2
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?

Nov 20 '06 #3
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.
-----------------------------
"GeekyChicky79" <sk******@aol.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.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?

Nov 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
2
by: Rose | last post by:
Hi all, I'm a newbie to C# and .NET, so please be gentle! My limited background is in VBScript,ASP, and Access dbs. I need to retrieve data from a SQL server db (8.0) to be displayed in a...
0
by: James Dean | last post by:
I have trouble displaying a bitmap. I have 1bpp information. I also have a command telling me what color i need to set the bytes to when the colour is switched on. The trouble is i do all this but...
7
by: Terry | last post by:
I have a Mainform with a Statusbar. When opening another form or doing some processing I want to display info in the Statusbar of the Mainform. I have read a lot of articles on this & have come up...
1
by: Flack | last post by:
Hey guys, Here is the scenario: I have the main form open and a background thread is running. The background thread sometimes needs access to the main forms graphics object and gets it by...
3
by: raj chahal | last post by:
Hi there I've created a db field with Memo type, and I have stored some text with carriage returns (no html) So the 3 words start on a differnt line. In access this displays correctly ( each...
10
by: gnewsgroup | last post by:
I've googled and tried various approaches, but could not resolve this problem. The article at MSDN: Displaying Images in a GridView Column only presents a simple case where all data (including the...
1
by: Jeremy.Campbell | last post by:
I am trying to add a picture to a form that is visible depending on certain criteria. The picture works perfectly on my computer, but on other users computers this image is either black or...
10
by: Clamato | last post by:
Good Morning, I'm working with a form that basically add's a users windows logon ID, first name, and last name to a table. A list box on this form is then requeried once added displaying the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.