本文介绍了想要下一个表单中的上一个表单的条目datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想在下一个表格datagridview中输入上一个表格的条目.
我在第二个表单的表单加载事件上尝试了此编码:
hi all,
i want to enter the entries of previous form in next form datagridview.
i tried out this coding on form load event of second form:
Program.adpt = new System.Data.SqlClient.SqlDataAdapter("select * from visitor_details", Program.con);
DataSet ds;
ds = new DataSet();
Program.adpt.Fill(ds);
for (int i = 0; i < 100; i++)
{
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = ds.Tables[0].Rows[i]["name"].ToString();
dataGridView1.DataSource = ds.Tables[0].Rows[i]["company"].ToString();
dataGridView1.DataSource = ds.Tables[0].Rows[i]["phone"].ToString();
dataGridView1.DataSource = ds.Tables[0].Rows[i]["visitor_type"].ToString();
dataGridView1.DataSource = ds.Tables[0].Rows[i]["in_time"];
dataGridView1.DataSource = ds.Tables[0].Rows[i]["host_name"].ToString();
dataGridView1.DataSource = ds.Tables[0].Rows[i]["initials"].ToString();
但是我收到一个错误位置0没有行".
任何人都可以解决这个问题.
预先感谢
neaS
But i get an error "there is no row at position 0".
can anybody sort this problem out.
thanxs in advance
neaS
推荐答案
Program.adpt = new System.Data.SqlClient.SqlDataAdapter("select * from visitor_details", Program.con);
DataSet ds;
ds = new DataSet();
Program.adpt.Fill(ds);
if(ds.Tables[0].Rows.Cont > 0)
{
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = ds.Tables[0];
}
Program.adpt = new System.Data.SqlClient.SqlDataAdapter("select * from visitor_details", Program.con);
DataSet ds;
ds = new DataSet();
Program.adpt.Fill(ds);
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource =ds;
这篇关于想要下一个表单中的上一个表单的条目datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!