TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
peter piper
NA
22
3.9k
How to create master detail Select query
Feb 12 2017 5:40 PM
I have a form and 2 sql tables. Table 1 contains header info and table 2 details info
A button that starts the process of writing data from the tables to an application.
private void button1_Click(object sender, EventArgs e)
{
using (SqlCommand cmd = new SqlCommand(@SELECT col1,col2,col3,col4 FROM tbl1,conn))
using (var rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
writeHeadData(rdr[“col1”], rdr[“col2”], rdr[“col3”], rdr[“col3”],rdr[“col4”]);
}
}
private void writeHeadData(string col1,string col2,string col3,string col4)
{
//do something here (writeHeadData)
writeDetailData(col1, col2, col3, col4)
}
private void writeDetailData(string col1,string col2,string col3,string col4)
{
//do something here with data from the details table
}
Where do I put the query from the detail table (see below) and ensure that the detail info relates to the header info using the WHERE clause
using (SqlCommand cmd = new SqlCommand(@SELECT * FROM tbl2,conn))
using (var rdr = cmd.ExecuteReader())
while (rdr.Read())
{
writeHeadData(rdr[“col1”], rdr[“col2”], rdr[“col3”], rdr[“col3”],rdr[“col4”]);
}
There are 3 details rows for every header row
I hope whoever reads this understands what I’am trying to achieve and if not clear please tell me and I shall try and elucidate further
Reply
Answers (
11
)
Why we use static class?
How can we get static access-token from facebook ?