コード例 #1
0
        public static int Update(mtDescription d)
        {
            string SQL_INSERT = @"INSERT INTO dbo.mt_Description (title, description, status, DisableStatus) VALUES (@title, @description, @status, 0); SELECT @@IDENTITY;";
            string SQL_UPDATE = @"UPDATE dbo.mt_Description SET title = @title, description = @description, status=@status, DisableStatus = 0 WHERE id = @id";

            using (SqlConnection cn = new SqlConnection(Config.ConnectionString))
            {
                cn.Open();
                SqlCommand cmd;
                if (d.id > 0)
                {
                    cmd = new SqlCommand(SQL_UPDATE, cn);
                    cmd.Parameters.Add("@id", SqlDbType.Int).Value                    = d.id;
                    cmd.Parameters.Add("@title", SqlDbType.VarChar, 100).Value        = d.title;
                    cmd.Parameters.Add("@description", SqlDbType.VarChar, 1000).Value = d.description;
                    cmd.Parameters.Add("@status", SqlDbType.Bit).Value                = d.status;
                    cmd.ExecuteNonQuery();
                }
                else
                {
                    cmd = new SqlCommand(SQL_INSERT, cn);
                    cmd.Parameters.Add("@title", SqlDbType.VarChar, 100).Value        = d.title;
                    cmd.Parameters.Add("@description", SqlDbType.VarChar, 1000).Value = d.description;
                    cmd.Parameters.Add("@status", SqlDbType.Bit).Value = d.status;
                    d.id = Convert.ToInt32(cmd.ExecuteScalar());
                }
            }
            return(d.id);
        }
コード例 #2
0
        public static mtDescription GetDescription(int id)
        {
            string sSQL = "SELECT * FROM dbo.mt_Description WHERE id=@id and DisableStatus=0 order by title";

            using (SqlConnection cn = new SqlConnection(Config.ConnectionString))
            {
                cn.Open();
                SqlCommand cmd = new SqlCommand(sSQL, cn);
                cmd.Parameters.Add("@id", SqlDbType.Int).Value = id;
                SqlDataReader rs = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                if (!rs.Read())
                {
                    return(null);
                }
                mtDescription d = new mtDescription();
                d.id          = (int)rs["id"];
                d.title       = rs["title"] + "";
                d.description = rs["description"] + "";
                d.status      = Convert.ToBoolean(rs["status"]);
                return(d);
            }
        }