public static bool InsertNewComment(Comments comments) { SqlCommand sqlcmd; SqlConnection sqlconnecnt = Common.SqlProvider.SelectGetConnection(); try { sqlconnecnt.Open(); sqlcmd = new SqlCommand("sp_insertnewcomment", sqlconnecnt); sqlcmd.Parameters.Add("newsid", SqlDbType.Int).Value = comments.NewsId; sqlcmd.Parameters.Add("author", SqlDbType.NVarChar).Value = comments.Author; sqlcmd.Parameters.Add("email", SqlDbType.NVarChar).Value = comments.Email; sqlcmd.Parameters.Add("content", SqlDbType.NVarChar).Value = comments.Content; sqlcmd.CommandType = CommandType.StoredProcedure; sqlcmd.ExecuteNonQuery(); return true; } catch(SqlException) { sqlconnecnt.Close(); return false; } finally { sqlconnecnt.Close(); } }
public static bool InsertNewComments(Comments comments) { if (comments.NewsId < 1) return false; if (comments.Author.Length < 5) return false; if (comments.Email.Length<5) return false; if (comments.Content.Length < 10 && comments.Content.Length < 500) return false; return CommentDao.InsertNewComment(comments); }
protected void ButtonComments_Click(object sender, EventArgs e) { if (CheckError()) { Comments cm = new Comments(); cm.Author = txtYourName.Text; cm.NewsId = NewId; cm.Email = txtEmail.Text; cm.Content = txtComment.Text; CommentsBU.InsertNewComments(cm); } }