• 利用DataAdapter於數擾庫同步


                SqlConnection conn = new SqlConnection("Data Source=192.168.27.12,10086;User ID=XX;Password=XX;Initial Catalog=XXX;Pooling=true");
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }

            
                DataSet ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter();
                da.SelectCommand = new SqlCommand("select * from businesses ORDER BY TimeCreated DESC", conn);
                SqlCommandBuilder commandbuilder= new SqlCommandBuilder(da);  //用到sqlCommandBuildetr對像
                da.Fill(ds);
                conn.Close();

                Console.WriteLine(ds.Tables[0].Rows[0][0].ToString());


                DataTable dt = ds.Tables[0];

                Console.WriteLine(dt.Rows[0].RowState);

                dt.Rows[0].Delete();
            
            /*
                這裏還可以對數據進行更新,插入操作
            更新操作:dt.Rows[1][0]="XXX"
                插入一行,則先要構建列與行DataColumn,DataRow,然後相應的加入到DataTable中
                dt.Rows[1].RowState
                Console.WriteLine(dt.Rows[0].RowState);
                */

                da.Update(ds);
                ds.AcceptChanges();
  • 相关阅读:
    Mac终端运行java程序
    Mac上csv导入mysql提示错误[Error Code] 1290
    Mac终端使用mysql
    将spark默认日志log4j替换为logback
    Cocos2d-x 3.x部署到安卓
    Cocos2d-x 3.0 场景切换
    visual studio 未将对象引用设置到对象的实例
    C++ list用法
    减而治之
    递归
  • 原文地址:https://www.cnblogs.com/wang123/p/1136499.html
Copyright © 2020-2023  润新知