コード例 #1
0
        public List <commentWCF> GetComments(int item_id)
        {
            List <commentWCF> comments = new List <commentWCF>();

            using (SqlConnection connection = new SqlConnection(Constants.SQLConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand("SELECT * from dbo.comments where item_id = @item_id  ORDER BY date_added DESC", connection))
                {
                    cmd.Parameters.AddWithValue("@item_id", item_id);
                    connection.Open();
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        // Check is the reader has any rows at all before starting to read.
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                commentWCF c = new commentWCF(
                                    reader.GetInt32(reader.GetOrdinal("id")),
                                    reader.GetInt32(reader.GetOrdinal("item_id")),
                                    reader.GetString(reader.GetOrdinal("user_id")),
                                    ResolveUserName(reader.GetString(reader.GetOrdinal("user_id"))),
                                    reader.GetString(reader.GetOrdinal("comment")),
                                    reader.GetDateTime(reader.GetOrdinal("date_added"))
                                    );

                                comments.Add(c);
                            }
                        }
                    }
                }
            }
            return(comments);
        }
コード例 #2
0
        public bool AddComment(commentWCF comment)
        {
            commentWCF c        = comment;
            int        affected = 0;


            using (SqlConnection connection = new SqlConnection(Constants.SQLConnectionString))

                using (SqlCommand cmd = new SqlCommand("INSERT INTO dbo.comments(item_id,user_id,comment,date_added) VALUES(@item_id,@user_id, @comment ,SYSDATETIME())", connection))
                {
                    //cmd.Parameters.AddWithValue("@id", c.id);
                    cmd.Parameters.AddWithValue("@item_id", c.item_id);
                    cmd.Parameters.AddWithValue("@user_id", c.user_id);
                    cmd.Parameters.AddWithValue("@comment", c.comment);

                    connection.Open();
                    affected = cmd.ExecuteNonQuery();
                }

            return(affected > 0 ? true : false);
        }
コード例 #3
0
 public bool AddComment(commentWCF comment)
 {
     return(DBACC.AddComment(comment));
 }