【发布时间】:2011-12-28 18:26:24
【问题描述】:
我有一个显示帖子的数据列表,我添加了用于添加评论的文本框和按钮,但是当我测试网站并添加评论时,我发现为帖子添加了正确的评论,但其余部分添加了空白评论的帖子...?
有谁知道我该如何处理这个问题?这是我的代码:
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'
【问题讨论】:
-
你能发布你的
comment存储过程吗? -
当然,我会添加程序,但正在等待编辑,我不知道为什么:D
-
好的,我现在看到了更新存储过程,而且看起来也没问题(除了用户永远不会看到 print 语句)。检索 cmets 的代码/存储过程怎么样?
-
通过从 cmets 表中选择comment.post_ID = control (post_IDLabel) 从数据列表中检索到的cmets
-
我现在看到了问题。我已经用解决方案更新了答案。
标签: c# asp.net visual-studio visual-studio-2010