Code代码片断(5do8)

GDI+控件线程IO流ADO.NET接口类,函数语法

新主题
c# cache与数据库映射
建立 CLR Stored Procedur...
access left join 两个
lucene.net提高查询速度
DataList 页面跳转
OnItemDataBound绑定事件
sql事务执行
SqlParameter添加数据
说话自由

首页 » .NET/C# » ADO.NET »

SqlParameter添加数据

标签: SqlParameter insert
public static int AddComment(Hashtable ht, string sTableName)
        {
            try
            {
                string sValue = String.Empty;
                int i = 0;
                SqlParameter[] objPar = new SqlParameter[ht.Count];
                foreach (DictionaryEntry key in ht)
                {
                    string sValueName = "@" + key.Key.ToString();
                    objPar[i] = new SqlParameter(sValueName, key.Value);
                    i++;
                    sValue += sValueName + ",";
                }
                if (sValue != String.Empty) sValue = sValue.Substring(0, sValue.Length - 1);
                string sql = string.Format("insert into {0} ({1}) values ({2})", sTableName, sValue.Replace("@", ""), sValue);
                MySql.Execute(sql, objPar);
                return 1;
            }
            catch
            {
                return 0;
            }
        }

ccdot写于2008-9-2 9:28:39

如果愿意,请留下你观点或者感受...
称呼*
内容*
验证码*