问题描述
学生表如下
studid studname minorcode
1 Ram AFF
2 Suresh MFA
3 Vignesh CTF
4 Sunil ROC
课程表如下
Courseid minorcode Amt Paymentmode
1 AFF 5000现金
2 MFA 8000现金
3 CTF 12000现金
4 ROC 16000现金
显示按钮中的代码如下
string minorcode;
sql =select s.studname,s.minorcode,c.Amt,c.Paymentmode from studnet s,course c where s.minorcode = c.minorcode
dr = scon。 ReadSql(sql);
while(dr.Read())
{
minorcode = dr [0] .ToString()。Trim();
sql =选择Amt,其中minorcode =''+ minorcode.ToString()。修剪()+'' ;
dr1 = scon.ReadSql(sql);
while(dr1.Read())
{
GridView.DataSource = dr;
GridView.DataBind();
GridView.Visible = true;
}
}
来自上面的编码我想在gridview中显示如下数据
在上面的代码我使用两个datareader(dr)dr和dr1。但我想显示一个GridView中显示的两个datareader值
for GridView我编写了上面的代码(GridView.DataSource = dr;)
如何在一个Gridview中显示两个datareader值。
i希望Gridview中的输出如下;
studname minorcode Amt Paymentmode
Ram AFF 5000现金
Suresh MFA 8000现金
Vignesh CTF 12000现金
Sunil ROC 16000现金
请帮助我。
我的代码是否正确。我试过但在gridview上面的输出没有显示。
问候,
Narasiman P.
student table as follows
studid studname minorcode
1 Ram AFF
2 Suresh MFA
3 Vignesh CTF
4 Sunil ROC
course table as follows
Courseid minorcode Amt Paymentmode
1 AFF 5000 Cash
2 MFA 8000 Cash
3 CTF 12000 Cash
4 ROC 16000 Cash
Code as follows in Show Button
string minorcode;
sql = "select s.studname,s.minorcode,c.Amt,c.Paymentmode from studnet s,course c where s.minorcode = c.minorcode
dr = scon.ReadSql(sql);
while (dr.Read())
{
minorcode = dr[0].ToString().Trim();
sql = "Select Amt from course where minorcode = ''" + minorcode.ToString().Trim() + "''";
dr1 = scon.ReadSql(sql);
while (dr1.Read())
{
GridView.DataSource = dr;
GridView.DataBind();
GridView.Visible = true;
}
}
from the above coding i want to show the data in gridview as follows
in my above code i am using two datareader(dr) dr and dr1. but i want to show the two datareader values shown in one GridView
for GridView i written the code as above (GridView.DataSource = dr;)
how can i display two datareader values in one Gridview.
i want the output as follows in Gridview;
studname minorcode Amt Paymentmode
Ram AFF 5000 Cash
Suresh MFA 8000 Cash
Vignesh CTF 12000 Cash
Sunil ROC 16000 Cash
please help me.
whether my code is correct.i tried but in gridview above output is not displaying.
Regards,
Narasiman P.
推荐答案
这篇关于如何在一个gridview中显示两个datareader值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!