using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace student
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{ } private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“dB_STDataSet1.Student”中。您可以根据需要移动或删除它。
this.studentTableAdapter.Fill(this.dB_STDataSet.Student);
}
private void button1_Click_1(object sender, EventArgs e)
{
SqlConnection lo_conn = new SqlConnection("Server=.;Database=DB_ST;;Integrated Security=True");
lo_conn.Open();
SqlCommand lo_cmd = new SqlCommand(); //创建命令对象
//写SQL语句
lo_cmd.Connection = lo_conn;
DataGridViewRow row = dataGridView1.Rows[dataGridView1.Rows.Count-2];
foreach (DataGridViewCell item in row.Cells)
{
lo_cmd.CommandText = "insert into student values('item','item','item','item','item')";
}
SqlDataAdapter dbAdapter = new SqlDataAdapter(lo_cmd); //注意与上面的区分开
DataSet ds = new DataSet(); //创建数据集对象
dbAdapter.Fill(ds);
lo_conn.Close();
this.studentTableAdapter.Fill(this.dB_STDataSet.Student);
} private void button2_Click_1(object sender, EventArgs e)
{ SqlConnection lo_conn = new SqlConnection("Server=.;Database=DB_ST;;Integrated Security=True");
lo_conn.Open();
SqlCommand lo_cmd = new SqlCommand(); //创建命令对象
lo_cmd.CommandText = "delete from student where sno='1'"; //写SQL语句
lo_cmd.Connection = lo_conn;
SqlDataAdapter dbAdapter = new SqlDataAdapter(lo_cmd); //注意与上面的区分开
DataSet ds = new DataSet(); //创建数据集对象
dbAdapter.Fill(ds);
lo_conn.Close();
this.studentTableAdapter.Fill(this.dB_STDataSet.Student);
}
}
}
这个是源代码,请问这个里面怎么加入数据?
DataGridViewRow row = dataGridView1.Rows[dataGridView1.Rows.Count-2];
foreach (DataGridViewCell item in row.Cells)
{
lo_cmd.CommandText = "insert into student values('item','item','item','item','item')";
}
谢谢啦!
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace student
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{ } private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“dB_STDataSet1.Student”中。您可以根据需要移动或删除它。
this.studentTableAdapter.Fill(this.dB_STDataSet.Student);
}
private void button1_Click_1(object sender, EventArgs e)
{
SqlConnection lo_conn = new SqlConnection("Server=.;Database=DB_ST;;Integrated Security=True");
lo_conn.Open();
SqlCommand lo_cmd = new SqlCommand(); //创建命令对象
//写SQL语句
lo_cmd.Connection = lo_conn;
DataGridViewRow row = dataGridView1.Rows[dataGridView1.Rows.Count-2];
foreach (DataGridViewCell item in row.Cells)
{
lo_cmd.CommandText = "insert into student values('item','item','item','item','item')";
}
SqlDataAdapter dbAdapter = new SqlDataAdapter(lo_cmd); //注意与上面的区分开
DataSet ds = new DataSet(); //创建数据集对象
dbAdapter.Fill(ds);
lo_conn.Close();
this.studentTableAdapter.Fill(this.dB_STDataSet.Student);
} private void button2_Click_1(object sender, EventArgs e)
{ SqlConnection lo_conn = new SqlConnection("Server=.;Database=DB_ST;;Integrated Security=True");
lo_conn.Open();
SqlCommand lo_cmd = new SqlCommand(); //创建命令对象
lo_cmd.CommandText = "delete from student where sno='1'"; //写SQL语句
lo_cmd.Connection = lo_conn;
SqlDataAdapter dbAdapter = new SqlDataAdapter(lo_cmd); //注意与上面的区分开
DataSet ds = new DataSet(); //创建数据集对象
dbAdapter.Fill(ds);
lo_conn.Close();
this.studentTableAdapter.Fill(this.dB_STDataSet.Student);
}
}
}
这个是源代码,请问这个里面怎么加入数据?
DataGridViewRow row = dataGridView1.Rows[dataGridView1.Rows.Count-2];
foreach (DataGridViewCell item in row.Cells)
{
lo_cmd.CommandText = "insert into student values('item','item','item','item','item')";
}
谢谢啦!
DataGrid要绑定DataMember DataTextField DataValueFied,这些都能在图形操作介面完成
最后的DataSource可以在后台绑定,绑定完以后,Refresh以下
string sql="xxx"
foreach(var item in xxx){
sql+=item.ToString()..
}
最后执行sql.