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类型,这里说的是支 ...
 
随机推荐
- CCPC L(水)
			
Huatuo's Medicine Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others ...
 - 2014 android毕设代做 代做Android毕设 安卓毕设
			
近期略有闲暇. 看到部分老友帮忙做毕业设计. 一来能够锻炼下小技能,二来能够得点零花小钱. 心遂小动.跃跃欲试. 毕设这件事情,个人觉得还是自己做的好. 只是每一个人都有各种各样的原因不能自己完毕. ...
 - 编译和安装shibboleth-sp遇到的问题
			
In file included from mod_shib_20.cpp:68: mod_shib.cpp:118: warning: deprecated conversion from stri ...
 - PHP程序猿必须学习的第二课——站点安全问题预防
			
作为PHP程序猿.第一课我们学习了基本的语法.那么在熟悉基本的语法之后我们应该学些什么呢?我觉得是安全问题.安全问题基于一个站点宛如基石,一着不慎,意味着灾难性的事故. 这里主要就提三点最简单,也是最 ...
 - css中的滤镜
			
前几天在做一个app应用的时候,用到了滤镜.在之前我只是知道有这么个东西,但是具体的知识点其实我是不太清楚的,所以为了让自己能深刻记忆,专门把它来记录一下.. 一.滤镜的标识符:“filter”;语法 ...
 - servlet response 中文乱码
			
先,response返回有两种,一种是字节流outputstream,一种是字符流printwrite. 申明:这里为了方便起见,所有输出都统一用UTF-8编码. 先说字节流,要输出“中国" ...
 - MVC3.0部署问题小结
			
环境:MVC3.0,IIS7 Mvc3.0的部署除像正常部署aspx程序一样外,另外还需要注意的几点:1. 安装MVC3.0 确保服务器上安装了MVC3.0,默认版本是“3.0.20105.0” 2. ...
 - Definitions
			
Definitions and ODR Definitions are declarations that fully define the entity introduced by the decl ...
 - mysql ifnull if
			
IFNULL(expr1,expr2) 如果expr1不是NULL,IFNULL()返回expr1,否则它返回expr2.IFNULL()返回一个数字或字符串值,取决于它被使用的上下文环境. mysq ...
 - Windows Phone 8初学者开发—第9部分:Windows Phone 8模拟器概述
			
原文 Windows Phone 8初学者开发—第9部分:Windows Phone 8模拟器概述 第9部分:Windows Phone 8模拟器概述 原文地址: http://channel9.ms ...