我有一个datalist显示帖子,我添加了用于添加评论的文本框和按钮,但是当我测试网站并添加评论时,我发现该评论已正确添加,但空白评论添加到其他职位......?datalist中的事件处理
任何人都知道我该如何处理?这里是我的代码:
protected void Button9_Click1(object sender, EventArgs e)
{
foreach (DataListItem item in DataList2.Items)
{
TextBox TextBox1 = (TextBox)item.FindControl("TextBox1");
string text = TextBox1.Text;
Label post_IDLabel = (Label)item.FindControl("post_IDLabel");
string connStr = ConfigurationManager.ConnectionStrings["MyDbConn"].ToString();
SqlConnection conn = new SqlConnection(connStr);
SqlCommand cmd = new SqlCommand("comment", conn);
cmd.CommandType = CommandType.StoredProcedure;
int post_ID = Convert.ToInt32(post_IDLabel.Text);
string comment = text;
string email = Session["email"].ToString();
int course_ID = Convert.ToInt32(Request.QueryString["courseID"]);
cmd.Parameters.Add(new SqlParameter("@course_ID", course_ID));
cmd.Parameters.Add(new SqlParameter("@comment", comment));
cmd.Parameters.Add(new SqlParameter("@myemail", email));
cmd.Parameters.Add(new SqlParameter("@postID", post_ID));
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
}
,这是注释程序
CREATE PROC comment
@comment VARCHAR (100),
@myemail VARCHAR (30),
@postID INT,
@course_ID INT
AS
IF @myemail IN (SELECT student_email FROM Students_Subscribes_Course_pages WHERE subscribed = 1)
OR @myemail IN (SELECT added_email FROM Lecturers_Adds_Academics_Course_page WHERE course_ID = @course_ID)
AND @postID IN (SELECT post_ID FROM Posts WHERE @postID = @postID) OR @myemail =
(SELECT page_creator FROM Course_pages WHERE course_ID = @course_ID) AND @postID IN
(SELECT post_ID FROM Posts)
INSERT INTO Members_Comments_Posts (commenter,post_ID, comment_content)
VALUES (@myemail, @postID, @comment)
ELSE
PRINT 'sorry, you are not subscribed or post not found'
你可以发布你的'评论'存储过程吗? – 2011-12-28 18:36:58
当然,我会添加过程,但编辑处于挂起状态,我不知道为什么:D – 2011-12-28 18:44:14
好吧,我现在看到更新存储过程,而且看起来还可以(除非用户永远不会看到打印语句) 。代码/存储过程如何检索评论? – 2011-12-28 19:27:44