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 对于这个复杂问题的解释说明
  • ¥50 三种调度算法报错 采用的你的方案
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败