一:将数据绑定到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. android 代码生成selector drawable

    public static StateListDrawable makeSelector(Context context, int idNormal, int idPressed, int idFoc ...

  2. oracle ||,

    || oracle数据库中的 ||称为 "字符串连接符" 用于连接查询结果,如下: select trade_id,accept_date from A; ------------ ...

  3. 更改yum源地址

    1.进入yum配置文件目录:cd /etc/yum.repos.d/ 2.备份配置文件:mv CentOS-Base.repo CentOS-Base.repo.bak 3.下载网易的配置,改成网易的 ...

  4. 线程,yield让出cpu调度

    public class Yield01 extends Thread { public static void main(String[] args) { new Yield01().start() ...

  5. [转]javascript eval函数解析json数据时为什加上圆括号eval("("+data+")")

    javascript eval函数解析json数据时为什么 加上圆括号?为什么要 eval这里要添加 “("("+data+")");//”呢?   原因在于: ...

  6. 莫名其妙MyEclipse

    MyEclipse Enterprise Workbench Version: 2015 Stable 2.0Build id: 13.0.0-20150518 整合SS时,\WEB-INF\clas ...

  7. KindEditor 编辑器使用方法

    http://kindeditor.net/docs/usage.html 编辑器使用方法 1. 下载编辑器 下载 KindEditor 最新版本,下载之后打开 examples/index.html ...

  8. pthon在Notepad++中执行方式

    使用 Notepad++ 编辑运行 Python 程序         Notepad++是一个开源的文本编辑器,功能强大而且使用方便.编辑和调试 Python 程序使用什么编辑器或者 IDE不同人有 ...

  9. oracle_exp_query_where_clause

    每次都忘记这个斜线,记录一下 exp img/123@orclxxx file=d:\bbb.dmp table=(ccc_tab) query=\"where id > 999\&q ...

  10. nginx相关的一些记录

    http redirect to https: if ($http_cf_visitor ~ '"scheme":"http"'){ rewrite ^/(.* ...