| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 793 人关注过本帖
标题:如何实现更新多条语句?
只看楼主 加入收藏
StrayInSky
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2007-11-28
收藏
 问题点数:0 回复次数:0 
如何实现更新多条语句?
下面代码只适用于所有表的单笔记录更新操作
/// <summary>
        /// 更新表的字段值
        /// </summary>
        /// <param name="Tablename">表名</param>
        /// <param name="keyname">Key数组</param>
        /// <param name="keyvalue">Keyvalue数组</param>
        /// <param name="column">字段名数组</param>
        /// <param name="value">字段名对应值</param>
        /// <returns>成功与否</returns>
        public virtual bool      UpdateTableRow(string Tablename, string[] keyname, string[] keyvalue, string[] column, string[] value)
        {
            if(InteropHelper.HasEmsInterfaces) //如果要求跨平台数据集成
            {
                //这是一个示例,跨平台操作可能不能传递DataTable,那么需要修改接口
                return InteropHelper.UpdateTableRow(Tablename, keyname, keyvalue, column, value);
            }
            #if DEBUG
            try
            {
            #endif
                //没有传入数组或数组对应字段不等
                if (column.Length < 1 || column.Length != value.Length || keyname.Length != keyvalue.Length) return false;
                string sqlString = Tablename + " set ";
                for(int i = 0;i < column.Length; i++ )
                {
                    sqlString = sqlString + column[i] + " = '" + value[i] + "'," ;
                }
                //去掉逗号
                sqlString = sqlString.Substring(0, sqlString.Length - 1);
                if(keyname.Length > 0)
                {
                    sqlString += " where ";
                    for(int j = 0; j < keyname.Length; j++)
                    {
                        sqlString = sqlString + keyname[j] + "= '" + keyvalue[j] + "' and";
                    }
                    //去掉" and"
                    sqlString = sqlString.Substring(0, sqlString.Length - 4);
                }
                sqlConnect.Open();
                SqlCommand updateCmd = new SqlCommand("Update " + sqlString,sqlConnect);
                updateCmd.ExecuteNonQuery();
                sqlConnect.Close();
                return true; //更新成功
            #if DEBUG
            }
            catch(Exception e)
            {
                sqlConnect.Close();
                ProcessLog("Error at UpdateTableRow:" + e);
                return false;  //更新失败
            }
            #endif
        }




要如何实现多笔记录的更新操作呢?
搜索更多相关主题的帖子: param 语句 name summary 
2008-05-16 11:18
快速回复:如何实现更新多条语句?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.077128 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved