• DbHelper简单的使用


    using System;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    
    namespace WindowsFormsApp3
    {
        public partial class FrmMain : Form
        {
            public FrmMain()
            {
                InitializeComponent();
            }
            private string index;
    
            //新增数据
            private void barLargeButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
            {
                string sql = @"INSERT INTO Person.ContactType
                                (Name)
                                VALUES
                                (@Name)";
                SqlParameter[] sqlParameter = new SqlParameter[1];
                sqlParameter[0] = new SqlParameter("@Name", "abbc");
                int i = DbHelper.ExecNonQuery(sql, sqlParameter);
                MessageBox.Show(i.ToString());
            }
    
            //加载数据
            private void Form1_Load(object sender, EventArgs e)
            {
                string sql = "SELECT ct.ContactTypeID, ct.Name, ct.ModifiedDate FROM Person.ContactType AS ct ";
                gridControl1.DataSource = DbHelper.GetDataTable(sql);
            }
    
            //更新数据
            private void barLargeButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
            {
                string sql = @"UPDATE Person.ContactType
                               SET Name = @Name
                               WHERE ContactTypeID=@ContactTypeID";
                SqlParameter[] sqlParameter = new SqlParameter[2];
                sqlParameter[0] = new SqlParameter("@Name", "Li Sir");
                sqlParameter[1] = new SqlParameter("@ContactTypeID", index);
                int i = DbHelper.ExecNonQuery(sql, sqlParameter);
                MessageBox.Show(i.ToString());
            }
    
            //获取单元格数据
            private void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
            {
                index = gridView1.GetRowCellDisplayText(e.RowHandle, "ContactTypeID");
            }
    
            //删除数据
            private void barLargeButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
            {
                string sql = @"DELETE FROM Person.ContactType
                               WHERE ContactTypeID=@ContactTypeID";
                SqlParameter[] sqlParameter = new SqlParameter[1];
                sqlParameter[0] = new SqlParameter("@ContactTypeID", index);
                int i = DbHelper.ExecNonQuery(sql, sqlParameter);
                MessageBox.Show(i.ToString());
            }
        }
    }

  • 相关阅读:
    Linux笔记(九)
    Linux笔记(八)
    Linux笔记(七)
    Linux笔记(五)
    Linux笔记(六)
    Linux笔记(四)
    Linux笔记(三)
    hdu 1009 qsort运用
    dfs模板 二部图的最大匹配
    拉格朗日函数c++
  • 原文地址:https://www.cnblogs.com/liessay/p/11866899.html
Copyright © 2020-2023  润新知