一:将数据绑定到dataGridView控件上。

string sqlconn = "server=.;database=student;integrated security=true";
try
{
string sqlcom = "select * from student_info";
SqlConnection conn = new SqlConnection(sqlconn);
SqlDataAdapter da = new SqlDataAdapter(sqlcom, conn);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[].DefaultView;
dataGridView1.AllowUserToAddRows = false;
conn.Close();
}

二:点击dataGridView的某一行将改行数据对应显示在textBox上。

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
try
{
snoTextBox.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["stu_sno"].Value.ToString();
nameTextBox.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["stu_name"].Value.ToString();
sexTextBox.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["stu_sex"].Value.ToString();
ageTextBox.Text = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["stu_age"].Value.ToString();
}
catch (Exception a)
{
MessageBox.Show(a.ToString());
}
}

将sqlserve数据绑定到dataGridView中及一些操作的更多相关文章

  1. [Winform] DataGridView 中 DataGridViewComboBox 的可编辑

    在 DataGridView 中设置的 DataGridViewComboBox,默认是不可编辑的,即使将其列属性 DisplayStyle 设置成 ComboBox 或其他,也无法编辑: 故作如下处 ...

  2. DataGridView中的Combobox的应用

    在WinForm中DataGridView可谓是应用比较多的数据显示控件了,DataGridView中可以应用各种控件,关于这样的文章网上 已有很多.都是实例化一个控件然后通过DataGridView ...

  3. 禁用datagridview中的自动排序功能

    把datagridview中的自动排序功能禁用自己收集的两种方法,看看吧①DataGridView中的Columns属性里面可以设置.进入"EditColumns"窗口后,在相应的 ...

  4. C#读取Excel表格数据到DataGridView中和导出DataGridView中的数据到Excel

    其实想在datagridview中显示excel表格中的数据跟读取数据库中的数据没什么差别,只不过是创建数据库连接的时候连接字段稍有差别. private void btnShow_Click(obj ...

  5. DataGridView中实现checkbox全选的自定义控件

    在DataGridView中实现Checkbox的全选的方法就是在列头画一个checkbox, 并给其一个事件. 这个之前很多blog都有写, 这里就不多废话了,  codeproject上面有示例代 ...

  6. c#.net循环将DataGridView中的数据赋值到Excel中,并设置样式

    Microsoft.Office.Interop.Excel.Application excel =                new Microsoft.Office.Interop.Excel ...

  7. DataGridView 中添加CheckBox和常用处理方式 .

    DataGridView 中添加CheckBox和常用处理方式 文章1 转载:http://blog.csdn.net/pinkey1987/article/details/5267934 DataG ...

  8. Datagridview 添加checkbox列,并判断Datagridview 中的checkbox列是否被选中

    Solution1://In Fill DataGridViewEvent : DataGridViewCheckBoxColumn ChCol = new DataGridViewCheckBoxC ...

  9. C#DataGridView中的常用技巧

    0(最基本的技巧). 获取某列中的某行(某单元格)中的内容  this.currentposition = this.dataGridView1.BindingContext  [this.dataG ...

随机推荐

  1. AMap编辑折线、多边形、圆

    <!doctype html> <html> <head> <meta charset="utf-8"> <meta http ...

  2. MVC 访问IFrame页面Session过期后跳转到登录页面

    Web端开发时,用户登录后往往会通过Session来保存用户信息,Session存放在服务器,当用户长时间不操作的时候,我们会希望服务器保存的Session过期,这个时候,因为Session中的用户信 ...

  3. Entity Framework 学习笔记

    1.自定义数据库链接字符串上下文 public class PetDbContext : DbContext { public PetDbContext() : base("name=Dem ...

  4. 利用外部表查询alert日志中的ora错误

    SQL> show parameter dump NAME                                 TYPE        VALUE------------------ ...

  5. 【摘】crontab 各时间含义

    HELL=/bin/bash <==使用哪種 shell 介面 PATH=/sbin:/bin:/usr/sbin:/usr/bin <==執行檔搜尋路徑 MAILTO=root < ...

  6. 压测如何观测jvm,就是使用jmx来实现jvm监控

    jps.jstack.jmap.jhat.jstat.hprof 基于jmx可以开发web版本,方便压测的时候观测jvm以及线程的信息 ================================ ...

  7. TP-link TL-WN725 USB无线网卡在DX2 CPU下的Xlinux 驱动移植

    网上查到,TP-link TL-WN725 USB无线网卡用的芯片是8188EU 下载驱动:http://download.csdn.net/detail/zzz_mraz/5262010 tar z ...

  8. 软件工程—我的IT的新篇章

    这学期开了一门软件工程,在开始学习过程中,我对软件工程充满了浓厚的兴趣,我很享受软件工程带给我的快乐与激情,让我对计算机编程更加的了解与享受,我非常的喜欢这门学科,我对老师的教学方式非常的喜欢,我觉得 ...

  9. SQLServer异步调用,批量复制

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  10. 跨境B2B网站

    大家都在谈跨境电商,其实现在比较火的应该是跨境B2B网站,它被很多的业内人士所看好,并且也取得了很喜人的成绩,无论是经营方面还是品牌打造,都从多方向带动了行业的发展. 跨境B2B网站 一.从买方市场向 ...