Beispiel #1
0
        public static string Insert(Hashtable has)
        {
            string id = (has["id"] == null || has["id"].ToString() == "") ? Guid.NewGuid().ToString() : has["id"].ToString();

            //has["id"] = id;
            has.Remove("id");

            string columns = "";
            string values  = "";

            foreach (DictionaryEntry de in has)
            {
                columns += "" + de.Key + ",";
                values  += "@" + de.Key + ",";
            }
            string sql = string.Format("insert into " + tbname + " ( {0} ) values( {1} ) ;SELECT @@Identity", columns.Substring(0, columns.Length - 1), values.Substring(0, values.Length - 1));

            DbConnection con = DBUtil.getConn();
            SqlCommand   cmd = new SqlCommand(sql, (SqlConnection)con);

            if (has != null)
            {
                DBUtil.SetArgs(sql, has, cmd);
            }
            id = cmd.ExecuteScalar().ToString();

            //插入datamain


            if (has["FNumber"] != null || has["FNumber"].ToString() != "")
            {
                string sql_mian = "INSERT INTO T_DataMain ([FPumpID],[FNumber]) VALUES ('" + id + "','" + has["FNumber"].ToString() + "')";
                DBUtil.Execute(sql_mian);
            }

            return(id);
        }