日期:2014-05-20 浏览次数:20883 次
/// <summary> /// 增加一条数据 /// </summary> public int Add(Five8.Model.Agency model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Agency("); strSql.Append("district,Area,Name,NetCode,NumberID)"); strSql.Append(" values ("); strSql.Append("@district,@Area,@Name,@NetCode,@NumberID)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@district", SqlDbType.VarChar,50), new SqlParameter("@Area", SqlDbType.VarChar,50), new SqlParameter("@Name", SqlDbType.VarChar,50), new SqlParameter("@NetCode", SqlDbType.VarChar,50), new SqlParameter("@NumberID", SqlDbType.VarChar,50)}; parameters[0].Value = model.district; parameters[1].Value = model.Area; parameters[2].Value = model.Name; parameters[3].Value = model.NetCode; parameters[4].Value = model.NumberID; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return 1; } else { return Convert.ToInt32(obj); } } [color=#FF0000]/// <summary> /// 执行一条计算查询结果语句,返回查询结果(object)。 /// </summary> /// <param name="SQLString">计算查询结果语句</param> /// <returns>查询结果(object)</returns> public static object GetSingle(string SQLString, params SqlParameter[] cmdParms) { using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand()) { try { PrepareCommand(cmd, connection, null, SQLString, cmdParms); object obj = cmd.ExecuteScalar(); cmd.Parameters.Clear(); if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value))) { return null; } else { return obj; } } catch (System.Data.SqlClient.SqlException e) { throw e; } finally { cmd.Dispose(); connection.Close(); } } } }[/color]
public static string Insert(Pt_Vender Obj) { try { DatabaseHelper.Insert<Pt_Vender>(Obj); return Obj.ID.ToString(); } catch (Exception ex) { throw new Exception(ex.Message); } }