国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

DataGrid中數據的增刪改向數據庫提交

2019-11-08 03:17:31
字體:
來源:轉載
供稿:網友

PRivate void button1_Click(object sender, System.EventArgs e)  {   //添加   string insStr = "Insert into test values(@vID, @vMC, @vDH, @vCZ, @vDZ)";   sda.InsertCommand = new SqlCommand(insStr, con);

   sPara = sda.InsertCommand.Parameters.Add("@vID", SqlDbType.VarChar);   sPara.SourceColumn = "id";   sPara.SourceVersion = DataRowVersion.Current;

   sPara = sda.InsertCommand.Parameters.Add("@vMC", SqlDbType.VarChar);   sPara.SourceColumn = "mingcheng";   sPara.SourceVersion = DataRowVersion.Current;

   sPara = sda.InsertCommand.Parameters.Add("@vDH", SqlDbType.VarChar);   sPara.SourceColumn = "dianhua";   sPara.SourceVersion = DataRowVersion.Current;

   sPara = sda.InsertCommand.Parameters.Add("@vCZ", SqlDbType.VarChar);   sPara.SourceColumn = "chuanzhen";   sPara.SourceVersion = DataRowVersion.Current;

   sPara = sda.InsertCommand.Parameters.Add("@vDZ", SqlDbType.VarChar);   sPara.SourceColumn = "dizhi";   sPara.SourceVersion = DataRowVersion.Current;

      if (ds.HasChanges())   {    sda.Update(ds, "test");    MessageBox.Show("插入記錄OK!");        }  }

  private void button2_Click(object sender, System.EventArgs e)  {   //修改更新   string updStr = "Update test set id = @vIDnew, MingCheng = @vMC, DianHua = @vDH, ChuanZhen = @vCZ, DiZhi = @vCZ  where id = @vIDold";   sda.UpdateCommand = new SqlCommand(updStr, con);

   sPara = sda.UpdateCommand.Parameters.Add("@vIDnew", SqlDbType.VarChar);   sPara.SourceColumn = "id";   sPara.SourceVersion = DataRowVersion.Current;

   sPara = sda.UpdateCommand.Parameters.Add("@vMC", SqlDbType.VarChar);   sPara.SourceColumn = "mingcheng";   sPara.SourceVersion = DataRowVersion.Current;

   sPara = sda.UpdateCommand.Parameters.Add("@vDH", SqlDbType.VarChar);   sPara.SourceColumn = "dianhua";   sPara.SourceVersion = DataRowVersion.Current;

   sPara = sda.UpdateCommand.Parameters.Add("@vCZ", SqlDbType.VarChar);   sPara.SourceColumn = "chuanzhen";   sPara.SourceVersion = DataRowVersion.Current;

   sPara = sda.UpdateCommand.Parameters.Add("@vDZ", SqlDbType.VarChar);   sPara.SourceColumn = "dizhi";   sPara.SourceVersion = DataRowVersion.Current;

   sPara = sda.UpdateCommand.Parameters.Add("@vIDold", SqlDbType.VarChar);   sPara.SourceColumn = "id";   sPara.SourceVersion = DataRowVersion.Original;

   if (ds.HasChanges())   {         sda.Update(ds, "test");          MessageBox.Show("數據更新OK!");   }  }

  private void button3_Click(object sender, System.EventArgs e)  {   //刪除   string delStr = "Delete from test where id = @vID";   sda.DeleteCommand = new SqlCommand(delStr, con);

   sPara = sda.DeleteCommand.Parameters.Add("@vID", SqlDbType.VarChar);   sPara.SourceColumn = "id";   sPara.SourceVersion = DataRowVersion.Original;

   if (MessageBox.Show("確實要刪除該紀錄嗎?","系統提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2,0)==DialogResult.Yes)   {       //ds.Tables[0].Rows[DataGrid_khxx.CurrentRowIndex].Delete();    sda.Update(ds, "test");    MessageBox.Show("刪除記錄OK!");   }  }

  private void button4_Click(object sender, System.EventArgs e)  {   Close();//關閉  }

  private void Form1_Load(object sender, System.EventArgs e)  {   //窗體載入事件   con = new SqlConnection("Server =.; Database = lesson; uid = sa; pwd = ");   con.Open();       sda = new SqlDataAdapter("select * from test", con);      sda.Fill(ds, "test");   con.Close();   DataGrid_khxx.DataSource = ds.Tables["test"];  }

===============================================

 public Cam(OleDbDataAdapter param_adapter, DataTable param_table)        {            g_adapter = param_adapter;            g_table = param_table;            string _strPath = AppDomain.CurrentDomain.BaseDirectory + "users.mdb";            string _strCon = "provider=microsoft.jet.oledb.4.0;data source="+_strPath;            g_con = new OleDbConnection(_strCon);                               }        public void upt(DataRow param_row)        {            string _strValue = "正常卡";            g_adapter.UpdateCommand = new OleDbCommand("update accountPersonInfoTable set cardState='" + _strValue + "' where num=@numValue", g_con);            g_adapter.UpdateCommand.Parameters.Add(_strValue, OleDbType.VarChar, 50, "cardState");            OleDbParameter _parameter= g_adapter.UpdateCommand.Parameters.Add("@numValue",OleDbType.VarChar);            _parameter.SourceColumn = "num";            _parameter.SourceVersion = DataRowVersion.Original;            param_row["cardState"] = _strValue;        }        public void cot()        {            g_adapter.Update(g_table);            g_table.AcceptChanges();        }

=====================

public class CDBOperation    {        private OleDbConnection g_con = null;        OleDbDataAdapter g_adapter = null;        public CDBoperation()        {            string _strPath = AppDomain.CurrentDomain.BaseDirectory + "users.mdb";            string _strCon = "provider=microsoft.jet.oledb.4.0;data source=" + _strPath;            g_con = new OleDbConnection(_strCon);            g_adapter = new OleDbDataAdapter();        }        public void update(DataTable param_newTable)        {            foreach (DataRow item in param_newTable.Rows)            {                if (item.RowState == DataRowState.Added)                {                    g_adapter.InsertCommand = new OleDbCommand("insert into machineSetTable (machineNum1,position1,communicateMode1,category1,ip1,port1,com1) values (@machineNum11,@position11,@communicateMode11,@category11,@ip11,@port11,@com11)",g_con);                    OleDbParameter _machineNumParam= g_adapter.InsertCommand.Parameters.Add("@machineNum11",OleDbType.VarChar);                    _machineNumParam.SourceColumn = "machineNum1";                    _machineNumParam.SourceVersion = DataRowVersion.Current;                    OleDbParameter _positionParam= g_adapter.InsertCommand.Parameters.Add("@position11",OleDbType.VarChar);                    _positionParam.SourceColumn = "position1";                    _positionParam.SourceVersion = DataRowVersion.Current;                    OleDbParameter _communicateModeParam= g_adapter.InsertCommand.Parameters.Add("@communicateMode11",OleDbType.VarChar);                    _communicateModeParam.SourceColumn = "communicateMode1";                    _communicateModeParam.SourceVersion = DataRowVersion.Current;                    OleDbParameter _categoryParam= g_adapter.InsertCommand.Parameters.Add("@category11",OleDbType.VarChar);                    _categoryParam.SourceColumn = "category1";                    _categoryParam.SourceVersion = DataRowVersion.Current;                    OleDbParameter _ipParam= g_adapter.InsertCommand.Parameters.Add("@ip11",OleDbType.VarChar);                    _ipParam.SourceColumn = "ip1";                    _ipParam.SourceVersion = DataRowVersion.Current;                    OleDbParameter _portParam= g_adapter.InsertCommand.Parameters.Add("@port11",OleDbType.VarChar);                    _portParam.SourceColumn = "port1";                    _portParam.SourceVersion = DataRowVersion.Current;                    OleDbParameter _comParam= g_adapter.InsertCommand.Parameters.Add("@com11",OleDbType.VarChar);                    _comParam.SourceColumn = "com1";                    _comParam.SourceVersion = DataRowVersion.Current;                }                else if (item.RowState == DataRowState.Modified)                {                    g_adapter.UpdateCommand = new OleDbCommand("update machineSetTable set machineNum1=@machineNum,position1=@position,communicateMode1=@communicate,category1=@category,ip1=@ip,port1=@port,com1=@com where id=@id1", g_con);                    OleDbParameter _machineNumParam = g_adapter.UpdateCommand.Parameters.Add("@machineNum", OleDbType.VarChar);                    _machineNumParam.SourceColumn = "machineNum1";                    _machineNumParam.SourceVersion = DataRowVersion.Current;                    OleDbParameter _positionParam= g_adapter.UpdateCommand.Parameters.Add("@position",OleDbType.VarChar);                    _positionParam.SourceColumn = "position1";                    _positionParam.SourceVersion = DataRowVersion.Current;                    OleDbParameter _communicateParam= g_adapter.UpdateCommand.Parameters.Add("@communicate",OleDbType.VarChar);                    _communicateParam.SourceColumn = "communicateMode1";                    _communicateParam.SourceVersion = DataRowVersion.Current;                    OleDbParameter _categoryParam= g_adapter.UpdateCommand.Parameters.Add("@category",OleDbType.VarChar);                    _categoryParam.SourceColumn = "category1";                    _categoryParam.SourceVersion = DataRowVersion.Current;                    OleDbParameter _ipParam= g_adapter.UpdateCommand.Parameters.Add("@ip",OleDbType.VarChar);                    _ipParam.SourceColumn = "ip1";                    _ipParam.SourceVersion = DataRowVersion.Current;                    OleDbParameter _portParam= g_adapter.UpdateCommand.Parameters.Add("@port",OleDbType.VarChar);                    _portParam.SourceColumn = "port1";                    _portParam.SourceVersion = DataRowVersion.Current;                    OleDbParameter _comParam= g_adapter.UpdateCommand.Parameters.Add("@com",OleDbType.VarChar);                    _comParam.SourceColumn = "com1";                    _comParam.SourceVersion = DataRowVersion.Current;                    OleDbParameter _idParam = g_adapter.UpdateCommand.Parameters.Add("@id1", OleDbType.Integer);                    _idParam.SourceColumn = "id";                    _idParam.SourceVersion = DataRowVersion.Original;                }                else if (item.RowState == DataRowState.Deleted)                {                    g_adapter.DeleteCommand = new OleDbCommand("delete from machineSetTable where id=@id",g_con);                    OleDbParameter _idParam= g_adapter.DeleteCommand.Parameters.Add("@id",OleDbType.Integer);                    _idParam.SourceColumn = "id";                    _idParam.SourceVersion = DataRowVersion.Original;                }            }            g_adapter.Update(param_newTable);            param_newTable.AcceptChanges();        }    }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 天等县| 阳东县| 越西县| 凌云县| 明星| 德江县| 老河口市| 平遥县| 寿光市| 襄垣县| 罗源县| 始兴县| 沐川县| 铜梁县| 汾阳市| 苏州市| 枣庄市| 靖宇县| 石景山区| 东宁县| 富锦市| 民丰县| 仙居县| 邮箱| 雅江县| 本溪| 磐安县| 牡丹江市| 景谷| 依兰县| 张家界市| 济南市| 仙桃市| 西平县| 许昌县| 彭泽县| 石楼县| 潜山县| 吴忠市| 广丰县| 江西省|