WinForm----DataGridview---连接数据库,以及双击一条数据,显示信息到Label控件,也可以是TextBox控件。
最终效果:

代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient; namespace Test
{
public partial class Form1 : Form
{
string constring = ConfigurationManager.ConnectionStrings["constring"].ConnectionString; public Form1()
{
InitializeComponent(); data();
} public void data()
{
using (SqlConnection con = new SqlConnection(constring))
{
con.Open(); string Sql = "select * from tb_Frinfo"; DataTable dt = new DataTable(); SqlDataAdapter dap = new SqlDataAdapter(Sql, con); dap.Fill(dt); this.dataGridView1.DataSource = dt;
}
} private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
this.label1.Text = this.dataGridView1.SelectedRows[].Cells[].Value.ToString();
this.label2.Text = this.dataGridView1.SelectedRows[].Cells[].Value.ToString();
this.label3.Text = this.dataGridView1.SelectedRows[].Cells[].Value.ToString();
this.label4.Text = this.dataGridView1.SelectedRows[].Cells[].Value.ToString();
this.label5.Text = this.dataGridView1.SelectedRows[].Cells[].Value.ToString();
this.label6.Text = this.dataGridView1.SelectedRows[].Cells[].Value.ToString();
this.label7.Text = this.dataGridView1.SelectedRows[].Cells[].Value.ToString();
this.label8.Text = this.dataGridView1.SelectedRows[].Cells[].Value.ToString();
} }
}
WinForm----DataGridview---连接数据库,以及双击一条数据,显示信息到Label控件,也可以是TextBox控件。的更多相关文章
- Winform 多个窗口编辑同一条数据同步的实现
场景: 一个主窗口中,可以在列表(DataGridView)里选中一条记录编辑,打开一个编辑窗口(非模态窗口),编辑窗口保存后需要刷新父窗口,由于编辑窗口是非模态窗口,如果打开了多个窗口,并且都是编辑 ...
- SQL 去重 显示第一条数据 显示一条数据
需求描述:根据某一个字段或几个字段去重来显示任一条数据,第一条或最后一条. 数据样式如下图: 尝试解决: --count(*)方法(只把条数为1条的显示出来了,超过1条全部过滤了) select * ...
- [WinForm]dataGridView动态加载以本地图片显示列
增加一个图片列: C# private void btnQuery_Click(object sender, EventArgs e) { StringBuilder sb=new StringBui ...
- WinForm DataGridView增删改查
DataGridView连接数据库对表进行增删改查 一.绑定数据源 //做一个变量控制页面刷新 ; public Form1() { InitializeComponent(); } private ...
- C# winform DataGridView 常见属性
C# winform DataGridView 属性说明① 取得或者修改当前单元格的内容 ② 设定单元格只读 ③ 不显示最下面的新行 ④ 判断新增行 ⑤ 行的用户删除操作的自定义 ⑥ 行.列的隐藏和删 ...
- winform datagridview控件使用
最近做项目时,显示查询结果总需要绑定到datagridview控件上显示,总结了给datagridview绑定数据的方式,以及导出datagridview数据到excel表格,如有错误请多指教 1.直 ...
- WinForm DataGridView根据选中的复选框删除
注意:在DataGridView添加一列(name:delete),ColumnType属性为:DataGridViewCheckBoxColumn,FlaseValue属性为:Flase,TureV ...
- 关于C# Winform DataGridView 设置DefaultCellStyle无效的原因与解决方案
上周在开发Winform 项目中,我曾遇到一个看似简单,但一直都没有解决的问题,那就是:设置winform DataGridView控件的行DefaultCellStyle,但却没有任何变化,我也曾求 ...
- C#实现WinForm DataGridView控件支持叠加数据绑定
我们都知道WinForm DataGridView控件支持数据绑定,使用方法很简单,只需将DataSource属性指定到相应的数据源即可,但需注意数据源必须支持IListSource类型,这里说的是支 ...
随机推荐
- Airport(未解决。。。)
Airport Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- DevExpress ASP.NET 使用经验谈(9)-Dev控件客户端事件 ClientSideEvents
上一节,已经介绍了ASPxGridView的自定义列和基本事件 ,本节接着将介绍Dev控件的客户端事件模型. 在上节示例基础上,我们增加一行菜单,使用Dev的ASPxMenu来实现,如下图所示. 图一 ...
- 字符串String类
1. String类是一个密封类.用关键字sealed修饰: 2. 字符串的两个特性: ·不可变性:string类型变量,一旦声明就表明它是不会被改变的.因此,string中的方法对strin ...
- OC中属性readwrite,readonly,assign,retain,copy,nonatomic 各是什么作用,在那种情况下用?
此次只做简单说明,不做代码演示! 1> readwrite:同时生成get方法和set方法的声明和实现 2> readonly:只生成get方法的声明和实现 3> assign:se ...
- Quiz 6b Question 8————An Introduction to Interactive Programming in Python
Question 8 We can use loops to simulate natural processes over time. Write a program that calcula ...
- BZOJ 1202: [HNOI2005]狡猾的商人( 差分约束 )
好像很多人用并查集写的... 前缀和, 则 sumt - sums-1 = v, 拆成2条 : sumt ≤ sums-1 + v, sums-1 ≤ sumt - v 就是一个差分约束, 建图跑SP ...
- HTML5 总结-拖放-3
HTML5 拖放 拖放(Drag 和 drop)是 HTML5 标准的组成部分. 拖放 拖放是一种常见的特性,即抓取对象以后拖到另一个位置. 在 HTML5 中,拖放是标准的一部分,任何元素都能够拖放 ...
- Zend Studio 如何配置本地apache服务器使用xdebug调试php脚本
本地环境搭配: apache 2.2 安装位置:D:/program files/Apache Software Foundation/Apache2.2 php 5.2.10 安装位置:C:/php ...
- Appium+Python app自动化测试之脚本启动和停止Appium服务
研究了一段时间的Appium android app的自动化测试,工作中需要连接多台手机终端同时执行测试用例,我实现的方式是获取用例中需要执行用例的设备id个数以及实际连接到的设备数(通过adb de ...
- python成长之路13
一:SqlAlchemy ORM ORM:Object Relational Mapping 对象关系映射是一种程序技术,用于实现面向对象编程语言里不同类型系统的数据之间的转换 SQLAlchemy是 ...