コード例 #1
0
    public static void SetPictureDetails(APicture picInfo)
    {
        SqlConnection dbConn = new SqlConnection(connectionString);

        SqlCommand sqlComm = new SqlCommand(
            @"UPDATE site_Picture
                SET Name = @name, Description = @description, Tags = @tags
                WHERE PicId = @pic_id", dbConn);

        sqlComm.Parameters.AddWithValue("pic_id", picInfo.Id);
        sqlComm.Parameters.AddWithValue("name", picInfo.Name);
        sqlComm.Parameters.AddWithValue("description", picInfo.Description);
        sqlComm.Parameters.AddWithValue("tags", picInfo.Tags);

        dbConn.Open();

        sqlComm.ExecuteNonQuery();

        dbConn.Close();
    }
コード例 #2
0
    public static APicture GetPictureDetails(string picId)
    {
        APicture pic = null;

        SqlConnection dbConn = new SqlConnection(connectionString);

        SqlCommand sqlComm = new SqlCommand(
            @"SELECT Description, Tags
              FROM site_Picture
              WHERE (PicId = @pic_id)", dbConn);

        sqlComm.Parameters.AddWithValue("pic_id", picId);

        dbConn.Open();

        using (SqlDataReader sqlDr = sqlComm.ExecuteReader(CommandBehavior.CloseConnection))
        {
            sqlDr.Read();

            try
            {
                pic = new APicture(null, null, sqlDr.GetString(0), sqlDr.GetString(1));
            }
            catch(Exception)
            {
                pic = new APicture(null, null, null, null);
            }

            sqlDr.Close();
        }

        return pic;
    }