0

我在这里要做的就是使用存储过程将状态字段设置为“完成”,但由于某种原因,在我运行存储过程后它没有更新我的表。有人可以在这里帮助我并告诉我我做错了什么吗?谢谢 //这里是存储过程

CREATE PROCEDURE sp_Update 
  @ID varchar 

AS 
BEGIN 
 -- SET NOCOUNT ON added to prevent extra result sets from 
 -- interfering with SELECT statements. 
 SET NOCOUNT ON; 

 if exists (select Post_ID from  MyTable  WHERE Post_ID = @ID) 
  BEGIN 
        UPDATE MyTable 
        SET Status = 'Complete' 
        WHERE Post_ID = @ID 
  END 

END 

//and here is the code behind 
foreach (GridViewRow gr in GV_Action.Rows) 
        { 

                //string strID = gr.Cells[1].Text; 
                string ID = gr.Cells[1].Text; 
                SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString); 

                SqlCommand cmd = new SqlCommand("sp_Update", con); 
                cmd.CommandType = CommandType.StoredProcedure; 

                cmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = ID; 

                cmd.Connection = con; 
                con.Open(); 
                cmd.ExecuteNonQuery(); 
                con.Close(); 

        }
4

1 回答 1

0

在代码“gr.Cells[1].Text”中,Cells[x] 从零开始。如果 ID 在第一列,那么您需要 'gr.Cells[0].Text'。在下一行放置一个断点,看看你在那里有什么价值。

于 2012-11-07T20:48:46.670 回答