本文介绍了从两个不同的表中获取数据并在c#.net中的单个datagridview中显示时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void AddProject_Load(object sender,EventArgs e)

{



OleDbConnection con = new OleDbConnection(constr);

OleDbCommand cmd = new OleDbCommand();



cmd.Connection = con;



cmd.CommandText =选择p.property_name,p.property_type_id,s.type_name来自tb_property p INNER JOIN lk_tb_property_type s ON p.property_type_id = s.property_type_id;

cmd.CommandType = CommandType.Text ;

OleDbDataAdapter da = new OleDbDataAdapter();

da.SelectCommand = cmd;

DataSet ds = new DataSet();

da.Fill(ds);

for(int i = 0; i< ds.Tables [0] .Rows.Count; i ++)

{



for(int j = 0; j< 2; j ++)

{

dataGridView1 .Rows.Add(new DataGridViewRow());

d ataGridView1.Rows [i] .Cells [j] .Value = ds.Tables [0] .Rows [i] [j] .ToString();

}

}

con.Close();

private void AddProject_Load(object sender, EventArgs e)
{

OleDbConnection con = new OleDbConnection(constr);
OleDbCommand cmd = new OleDbCommand();

cmd.Connection = con;

cmd.CommandText = "select p.property_name, p.property_type_id, s.type_name from tb_property p INNER JOIN lk_tb_property_type s ON p.property_type_id=s.property_type_id ";
cmd.CommandType = CommandType.Text;
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{

for (int j = 0; j < 2; j++)
{
dataGridView1.Rows.Add(new DataGridViewRow());
dataGridView1.Rows[i].Cells[j].Value = ds.Tables[0].Rows[i][j].ToString();
}
}
con.Close();

推荐答案

for (int j = 0; j < ; j++)





to



to

for (int j = 0; j < 3; j++)


这篇关于从两个不同的表中获取数据并在c#.net中的单个datagridview中显示时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 13:26