billrolbin 2022-03-11 19:44 采纳率: 80.8%
浏览 91
已结题

C# ado.net 我们一般是用ado.net来访问,查询,更新数据库,听说.net6不用这种方式,有没有相关的例子?

C# ado.net 我们一般是用ado.net来访问,查询,更新数据库,听说.net6不用这种方式,有没有相关的例子?
帮我写一个下面实现同样的功能的例子。谢谢!


 protected void Button2_Click(object sender, EventArgs e)
        {
            string myGPLEN = "Kill", myAvgCJJE = "0";
            string myXLH = "";
        
            string strSQL = " select * from RenYuan where   1=1  ";
        
            DataTable dt = new DataTable();
            dt = this.DB_GetDataTable(strSQL);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                myXLH = dt.Rows[i]["id"].ToString().Trim();

           myTempID = "01";
                myGPLEN = "2022-03-" + myTempID;

                //strSQL = "  update BL_LoveWorkA set BloodA='" + myTempID + "'  where XLH='" + myXLH + "'";

                strSQL = "  update RenYuan set createtime='" + myGPLEN + "'  where id='" + myXLH + "'";
                DB_ExecuteSQL(strSQL);


            }

        }

  public int DB_ExecuteSQL(string SQLString)
        {

            #region 执行SQL
            string strConnID = "";
            strConnID = "Server=101.43.288.289;Database=DBTuShuGuan;User Id=sa;Password=robinsoft;Connect Timeout=30;min pool size=10;Max Pool Size=1000;Pooling=true;packet size=3072";
            using (SqlConnection connection = new SqlConnection(strConnID))
            {
                using (SqlCommand cmd = new SqlCommand(SQLString, connection))
                {
                    try
                    {
                        connection.Open();
                        int rows = cmd.ExecuteNonQuery();
                        return rows;
                    }
                    catch (System.Data.SqlClient.SqlException E)
                    {
                        connection.Close();
                        throw new Exception(E.Message);
                    }
                }
            }
            #endregion

        }

 public DataTable DB_GetDataTable(string SQLString)
        {

            #region  获取数据表 DataTable
            string strConnID = "";
            strConnID = "Server=101.43.288.279;Database=DBTuShuGuan;User Id=sa;Password=robinsoft;Connect Timeout=30;min pool size=10;Max Pool Size=1000;Pooling=true;packet size=3072";
            using (SqlConnection connection = new SqlConnection(strConnID))
            {
                DataTable dt = new DataTable();
                dt.Clear();
                try
                {
                    connection.Open();
                    SqlDataAdapter command = new SqlDataAdapter(SQLString, connection);
                    command.Fill(dt);
                    command.Dispose();
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    throw new Exception(ex.Message);
                }
                return dt;
            }
            #endregion

        }

  • 写回答

3条回答 默认 最新

查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 3月21日
  • 已采纳回答 3月13日
  • 创建了问题 3月11日

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助