zoukankan      html  css  js  c++  java
  • SqlCommandBuilder对像来自动构建sql命令

    string sConnectonString;
                sConnectonString 
    = "Password=sa;user id = sa;Initial Catalog = master;Data Source=(local)";
                SqlConnection objConn 
    = new SqlConnection(sConnectonString);
                objConn.Open();
                           
                SqlDataAdapter daAuthors 
    = new SqlDataAdapter("select * from city_users", objConn);
                DataSet dsMaster 
    = new DataSet("master");
                daAuthors.FillSchema(dsMaster, SchemaType.Source, 
    "city_users");//加载表的构架,这样在操作加载到dataset里的表时就不用重新设置主键了
                daAuthors.Fill(dsMaster, "city_users");
                dsMaster.Tables[
    "city_users"].Rows[1]["user_name"= "sql";//注意这里的Rows[1],这个1指得是在DataSet里的表里的行号,其与数据库里的行号不一致如图1
                
                SqlCommandBuilder objCommandBuilder 
    = new SqlCommandBuilder(daAuthors);//构建sql命令
                daAuthors.Update(dsMaster, "city_users");//更新
                
    //daAuthors.UpdateCommand = updatecomm;
                
    //daAuthors.UpdateCommand.ExecuteNonQuery();
                objConn.Close();
  • 相关阅读:
    一道sql面试题
    Jedis操作redis入门
    SparkStreaming以Direct的方式对接Kafka
    SparkStreaming基于Receiver的方式对接Kafka
    spark-streaming对接kafka的两种方式
    RDD-aggregateByKey
    RDD-aggregate
    RDD五大特性
    Spark广播变量
    Spark RDD计算每天各省的top3热门广告
  • 原文地址:https://www.cnblogs.com/RobotTech/p/616141.html
Copyright © 2011-2022 走看看