本文介绍了想要下一个表单中的上一个表单的条目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
推荐答案尝试一下. Try this. 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]; }
最好在开始工作之前对绑定DataGridView有一定的了解如何在C#中使用SQL语句填充DataGridView,GridView [ ^ ] Better before start working have some knowledge on binding the DataGridView How to populate DataGridView, GridView with SQL statement in C#[^] 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
发布评论