c# 从零到精通 读取连接数据库-并将数据填入dataGridView控件中,并且获取所选单元格的值
using System;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Test02
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection conn;
SqlDataAdapter sda;
DataSet ds = null;
private void Form1_Load(object sender, EventArgs e)
{
conn = new SqlConnection(“server=MRC-8CF94303A82\MRNET;database=db_16;uid=sa;pwd=111”);
sda = new SqlDataAdapter(“select * from tb_teacher”, conn);
ds = new DataSet();
sda.Fill(ds, “teacher”);
dataGridView1.DataSource = ds.Tables[0];
}
private void button1_Click(object sender, EventArgs e)
{
string msg = String.Format(“第{0}行,第{1}列”, dataGridView1.CurrentCell.RowIndex,
dataGridView1.CurrentCell.ColumnIndex);
label1.Text = “选择的单元格为:” + msg;
}
}
}文章来源地址https://www.toymoban.com/news/detail-490143.html
文章来源:https://www.toymoban.com/news/detail-490143.html
到了这里,关于c# 从零到精通 读取连接数据库-并将数据填入dataGridView控件中,并且获取所选单元格的值的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!