我有一個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