使用DataGridView更新数据库
来源:互联网 发布:rrelieff算法 编辑:程序博客网 时间:2024/05/17 08:57
习惯了BCB 中的Dbgrid 的方便操作,想在VS C#里也这样,可是还真是不容易.费了好大功夫,总算好一点了
不过感觉挺麻烦的.这个DataGridView很不省事.
可以通过点击按钮,来提交数据了...
public partial class Form1 : Form
{
#region Form1数据成员
private DataTable DT = new DataTable();
private SqlDataAdapter SDA = new SqlDataAdapter();
#endregion
#region Form1构造函数
public Form1()
{
InitializeComponent();
}
#endregion
#region 连接数据库显示数据
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=127.0.0.1;database=pubs;uid=sa");
SqlCommand SCD = new SqlCommand("select * from tables", conn);
SDA.SelectCommand = SCD;
SDA.Fill(DT);
dataGridView1.DataSource = DT;
}
#endregion
#region 使用Update更新数据库
private void toolStripButton1_Click(object sender, EventArgs e)
{
try
{
SqlCommandBuilder SCB = new SqlCommandBuilder(SDA);
SDA.Update(DT);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
return;
}
MessageBox.Show("更新成功!");
}
#endregion
}
{
#region Form1数据成员
private DataTable DT = new DataTable();
private SqlDataAdapter SDA = new SqlDataAdapter();
#endregion
#region Form1构造函数
public Form1()
{
InitializeComponent();
}
#endregion
#region 连接数据库显示数据
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=127.0.0.1;database=pubs;uid=sa");
SqlCommand SCD = new SqlCommand("select * from tables", conn);
SDA.SelectCommand = SCD;
SDA.Fill(DT);
dataGridView1.DataSource = DT;
}
#endregion
#region 使用Update更新数据库
private void toolStripButton1_Click(object sender, EventArgs e)
{
try
{
SqlCommandBuilder SCB = new SqlCommandBuilder(SDA);
SDA.Update(DT);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
return;
}
MessageBox.Show("更新成功!");
}
#endregion
}
- 使用DataGridView更新数据库
- DataGridView更新数据库
- dataGridView更新数据库
- 通过DataGridView更新数据库
- datagridview 更新数据库
- sql+datagridview 更新数据库
- dataGridView更新数据库
- DataGridView(C#使用SqlDataAdapter.Update更新数据库)
- datagridview的使用,即时新增,更新,删除数据库数据
- C#winform dataGridView更新数据库
- C#winform dataGridView更新数据库
- DataGridView数据更新至数据库-逐条更新
- DataGridView数据更新至数据库-整体更新
- dataGridView中更新数据到数据库中
- DataGridView和数据库之间的双向更新
- datagridview更新到数据库视频教程地址
- 从datagridview更新到数据库方法
- 删除Datagridview选中行并更新数据库
- string类c++实现
- DataGridView的具体应用(1)-右键单击后选中所在行及弹出上下文菜单,通过事件捕获所选行的ID号及单元格内容
- Java手机软件图形界面API之Form相关API(转)
- 五子棋的核心算法(转)
- <<飞 鸟 集>> 泰戈尔
- 使用DataGridView更新数据库
- 在DataGridView中获得DataGridViewCheckBoxColumn的状态
- Queue c++实现
- c#的坎坷旅途
- 何为爱情?
- 无聊 经济学
- BBS的初稿模型
- 使用 MMAnalyzer 发现内存不足 (out of memory java heap)解决方法
- 修改oracle数据库字符集的方法