想要下一个表单中的上一个表单的条目datagridview

编程入门 行业动态 更新时间:2024-10-27 22:30:29
本文介绍了想要下一个表单中的上一个表单的条目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

本文发布于:2023-10-12 21:44:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485984.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   条目   datagridview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!