zoukankan      html  css  js  c++  java
  • 更新DataGridVeiw中的数据到后台数据库中

    标签: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(
    "更新成功!");
            }

  • 相关阅读:
    [知乎作答]·关于在Keras中多标签分类器训练准确率问题
    [深度应用]·Keras极简实现Attention结构
    工作队列work queues 公平分发(fair dispatch) And 消息应答与消息持久化
    RabbitMQ 之 WorkQueues工作队列
    RabbitMQ初体验
    RabbitMQ 简单了解以及使用
    画龙点睛 之RabbitMQ 初来乍到
    JVM 深入浅出
    HashMap和ConcurrentHashMap和HashTable的底层原理与剖析
    Lucene
  • 原文地址:https://www.cnblogs.com/xingchen/p/2030347.html
Copyright © 2011-2022 走看看