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
Loading

Nitin SontakkeRank #264 · 9.6K reputationPosted Feb 12, 2017, 5:18 PM EST
peter piper20 reputationPosted Feb 12, 2017, 11:51 PM EST
Nitin SontakkeRank #264 · 9.6K reputationPosted Feb 13, 2017, 12:37 AM EST
peter piper20 reputationPosted Feb 13, 2017, 12:53 AM EST
Nitin SontakkeRank #264 · 9.6K reputationPosted Feb 13, 2017, 1:55 AM EST
peter piper20 reputationPosted Feb 13, 2017, 5:51 AM EST
peter piper20 reputationPosted Feb 13, 2017, 7:12 AM EST
Nitin SontakkeRank #264 · 9.6K reputationPosted Feb 13, 2017, 5:29 PM EST
peter piper20 reputationPosted Feb 13, 2017, 11:47 PM EST
peter piper20 reputationPosted Feb 14, 2017, 2:28 AM EST
Nitin SontakkeRank #264 · 9.6K reputationPosted Feb 14, 2017, 3:57 AM EST