473,395 Members | 1,583 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,395 software developers and data experts.

retrieve records from sqlserver w/ where clause

I have no problem setting the selectcommand in sqldataadapter to fetch
record from sqlserver w/ where clause in parent table. however, my
problem is on how can i fetch the child table which is related from
the parent table.

I have ask this before and may be have not explained it well that's
why i can't still get what i need.

i have three tables that is related from each other.
students table
schyrsem table
schyrsemcourse table

i'll give some of the field for each table to give a thorough example

students table consist of:
idno
lastname
firstname

schyrsem table
schyrsemid
idno
schyr

schyrsemcourse table
schyrsemcourseid
schyrsemid
course

as you can see STUDENTS and SCHYRSEM table is related using IDNO and
SCHYRSEM and SCHYRSEMCOURSE table is also related using SCHYRSEMID.

now in my sqldataadapter for students table i have setup the
selectcommand using this sql "select idno, lastname, firstname from
students where lastname = @lastname"

i don't have problem retrieving record in students and schyrsem table
but the big problem is on the third table (schyrsemcourse)

students table is displayed using textboxes and schyrsem is displayed
using a datagrid.

so my sqldataadapter selectcommand statement is something like this.
"select schyrsemid, idno, schyr from schyrsem where idno = @idno"
and the parameter is this
daSchYrSem.SelectCommand.Parameters("@IDNo").Value = IDNo.Text

this is seems very easy w/ the 1st and 2nd table but the problem is in
the 3rd table because i don't know how to get the value of 2nd table
(based on a datagrid) in order to fetch the record in 3rd table.

i would be very glad if you can give me some clue or article to learn
on.

thanks in advance.
Nov 21 '05 #1
2 1600
If you are running from a student last name (not the wisest, as it is not
guaranteed unique, but good enough for our example), link everything back to
that name.

select idno, lastname, firstname from
students where lastname = @lastname

The second table:

select s.schyrsemid, s.idno, s.schyr from schyrsem s
join students st on s.idno = st.idno
students where st.lastname = @lastname

Third table:

select course from schyrsemcourse c
join schyrsem s
on c.schyrsemid = s.schyrsemid
join students st on s.idno = st.idno
students where st.lastname = @lastname

You now have data related to a single student. Personally, I do not like the
database design, as it is not as normal as it should be (based on what you
have given me).

You can link the three in a single sproc and return three tables. Use
TableMappings on the DataAdapter to give them friendly names.

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"jaYPee" wrote:
I have no problem setting the selectcommand in sqldataadapter to fetch
record from sqlserver w/ where clause in parent table. however, my
problem is on how can i fetch the child table which is related from
the parent table.

I have ask this before and may be have not explained it well that's
why i can't still get what i need.

i have three tables that is related from each other.
students table
schyrsem table
schyrsemcourse table

i'll give some of the field for each table to give a thorough example

students table consist of:
idno
lastname
firstname

schyrsem table
schyrsemid
idno
schyr

schyrsemcourse table
schyrsemcourseid
schyrsemid
course

as you can see STUDENTS and SCHYRSEM table is related using IDNO and
SCHYRSEM and SCHYRSEMCOURSE table is also related using SCHYRSEMID.

now in my sqldataadapter for students table i have setup the
selectcommand using this sql "select idno, lastname, firstname from
students where lastname = @lastname"

i don't have problem retrieving record in students and schyrsem table
but the big problem is on the third table (schyrsemcourse)

students table is displayed using textboxes and schyrsem is displayed
using a datagrid.

so my sqldataadapter selectcommand statement is something like this.
"select schyrsemid, idno, schyr from schyrsem where idno = @idno"
and the parameter is this
daSchYrSem.SelectCommand.Parameters("@IDNo").Value = IDNo.Text

this is seems very easy w/ the 1st and 2nd table but the problem is in
the 3rd table because i don't know how to get the value of 2nd table
(based on a datagrid) in order to fetch the record in 3rd table.

i would be very glad if you can give me some clue or article to learn
on.

thanks in advance.

Nov 21 '05 #2
WOW!

Thank you thank you very much. I don't know how to thank you but I
really appreciate your help. It works!

I am also open to your suggestion on how can I normalize my table.
From now on I'm relying to my database design.

Hope to hear from you soon about your suggestion.

Thank you once again.
On Thu, 9 Dec 2004 11:18:55 -0800, "Cowboy (Gregory A. Beamer) - MVP"
<No************@comcast.netNoSpamM> wrote:
If you are running from a student last name (not the wisest, as it is not
guaranteed unique, but good enough for our example), link everything back to
that name.

select idno, lastname, firstname from
students where lastname = @lastname

The second table:

select s.schyrsemid, s.idno, s.schyr from schyrsem s
join students st on s.idno = st.idno
students where st.lastname = @lastname

Third table:

select course from schyrsemcourse c
join schyrsem s
on c.schyrsemid = s.schyrsemid
join students st on s.idno = st.idno
students where st.lastname = @lastname

You now have data related to a single student. Personally, I do not like the
database design, as it is not as normal as it should be (based on what you
have given me).

You can link the three in a single sproc and return three tables. Use
TableMappings on the DataAdapter to give them friendly names.

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"jaYPee" wrote:
I have no problem setting the selectcommand in sqldataadapter to fetch
record from sqlserver w/ where clause in parent table. however, my
problem is on how can i fetch the child table which is related from
the parent table.

I have ask this before and may be have not explained it well that's
why i can't still get what i need.

i have three tables that is related from each other.
students table
schyrsem table
schyrsemcourse table

i'll give some of the field for each table to give a thorough example

students table consist of:
idno
lastname
firstname

schyrsem table
schyrsemid
idno
schyr

schyrsemcourse table
schyrsemcourseid
schyrsemid
course

as you can see STUDENTS and SCHYRSEM table is related using IDNO and
SCHYRSEM and SCHYRSEMCOURSE table is also related using SCHYRSEMID.

now in my sqldataadapter for students table i have setup the
selectcommand using this sql "select idno, lastname, firstname from
students where lastname = @lastname"

i don't have problem retrieving record in students and schyrsem table
but the big problem is on the third table (schyrsemcourse)

students table is displayed using textboxes and schyrsem is displayed
using a datagrid.

so my sqldataadapter selectcommand statement is something like this.
"select schyrsemid, idno, schyr from schyrsem where idno = @idno"
and the parameter is this
daSchYrSem.SelectCommand.Parameters("@IDNo").Value = IDNo.Text

this is seems very easy w/ the 1st and 2nd table but the problem is in
the 3rd table because i don't know how to get the value of 2nd table
(based on a datagrid) in order to fetch the record in 3rd table.

i would be very glad if you can give me some clue or article to learn
on.

thanks in advance.


Nov 21 '05 #3

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

Similar topics

8
by: tom | last post by:
I am new to SQL administration. >From a list of IDs that are the primary key in one table (i.e. Customer Table), I want to make changes in tables that use those IDs as a foreign key. ...
5
by: Roy Gourgi | last post by:
Hi, I am used to working in Visual FoxPro and I would like to be able to create a database and store and retrieve information from it. What is the simplest way to do it and what should I be...
12
by: jaYPee | last post by:
I have currently using a dataset to access my data from sql server 2000. The dataset contains 3 tables that is related to each other. parent/child/grandchild relationship. My problem is it's very...
5
by: JSParker1 | last post by:
Summary: Maximum number of records per second that can be inserted into SQLServer 2000. I am trying to insert hundreds (preferably even thousands) of records per second in to SQLServer table...
6
by: InnoCreate | last post by:
Hi everyone. I've recently written a classic asp website which uses an MS Access datasource. I know this is less than an ideal data source as it has limited functionality. I have a search form on...
1
by: mrkselm | last post by:
Hi, I am stuck with a problem in MS Access which does not occur in SQL Server and I have been banging my head against the wall for a couple of days now trying to resolve it. Namely, when I...
4
by: Simon Gare | last post by:
Hi all, I am trying to retrieve a count of booking entries made 30 days ago, below is the end of the query I am having problems with. dbo.booking_form.TimeOfBooking = DATEADD(day, -30,...
4
by: LetMeDoIt | last post by:
Greetings, I'm using ASP to retrieve from MSSQL and I then populate a table. After several months of successfull retrieves, this same code now bombs out. It turns out that if I clear out from...
1
by: ashishtech | last post by:
In the following query D_CNT_LINE_EXPIRE comparison with '2008-09-19' is failing altough value is there in this field. D_CNT_LINE_EXPIRE is a timestamp field in SQLSERVER table CCG03. I doubt...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.