Using System. Collections. Generic;
Using System.Com ponentModel;
Using System. The Data;
Using System. Drawing;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;
Using System. Windows. Forms;
Using System. The Data. SqlClient.
The namespace demo38
{
Public partial class Form1: Form
{
SqlConnection conn.
The DataSet ds;
SqlDataAdapter sda.
Public _click ()
{
InitializeComponent();
}
Private void label1_Click (object sender, EventArgs e)
{
}
Private void Form1_Load (object sender, EventArgs e)
{
Conn=new SqlConnection (" server=. The database=test3; Uid=sa; The PWD=123456 ");
SqlCommand CMD=new SqlCommand (" select * from Table_3 ", conn);
Sda=new SqlDataAdapter ();
Sda. SelectCommand=CMD;
Ds=new DataSet ();
Sda. The Fill (ds, "Table_3");
DataGridView1. The DataSource=ds. Tables [0];
}
Private void button1_Click (object sender, EventArgs e)
{
The DataTable dt=ds. Tables [" Table_3 "];
Sda. FillSchema (dt, SchemaType. Mapped);
DataRow Dr=dt. Rows. The Find (textBox1. Text);
Dr/" name "=textBox2. Text. The Trim ();
Dr (" gender ")=this. TextBox3. Text. The Trim ();
Dr (" age ")=this. TextBox4. Text. The Trim ();
Dr [" bonus "]=this. TextBox5. Text. The Trim ();
SqlCommandBuilder commandBuilder=new SqlCommandBuilder (sda);
Sda. Update (dt);
}
Private void dataGridView1_CellContentClick (object sender, DataGridViewCellEventArgs e)
{
TextBox1. Text=dataGridView1. SelectedCells [0]. Value. The ToString ();
TextBox2. Text=dataGridView1. SelectedCells [1]. The Value. The ToString ();
TextBox3. Text=dataGridView1. SelectedCells [2]. The Value. The ToString ();
TextBox4. Text=dataGridView1. SelectedCells [3]. The Value. The ToString ();
TextBox5. Text=dataGridView1. SelectedCells [4]. The Value. The ToString ();
}
}
}
Error
The database table
CodePudding user response:
Selected only one, don't want to get 5 selected cell data, but the index to blame,CodePudding user response:
Private void dataGridView1_CellContentClick (object sender, DataGridViewCellEventArgs e){
//textBox1. Text=dataGridView1. SelectedCells [0]. Value. The ToString ();
//textBox2. Text=dataGridView1. SelectedCells [1]. The Value. The ToString ();
//textBox3. Text=dataGridView1. SelectedCells [2]. The Value. The ToString ();
//textBox4. Text=dataGridView1. SelectedCells [3]. The Value. The ToString ();
//textBox5. Text=dataGridView1. SelectedCells [4]. The Value. The ToString ();
TextBox1. Text=dataGridView1. CurrentRow. Cells [0]. Value. The ToString ();
TextBox2. Text=dataGridView1. CurrentRow. Cells [1]. The Value. The ToString ();
TextBox3. Text=dataGridView1. CurrentRow. Cells [2]. The Value. The ToString ();
TextBox4. Text=dataGridView1. CurrentRow. Cells [3]. The Value. The ToString ();
TextBox5. Text=dataGridView1. CurrentRow. Cells [4]. The Value. The ToString ();
}
Has been solved, the details to see the introduction of the
https://blog.csdn.net/zhuzinanhua/article/details/82819777