// Append the last field, converting true/false values to 0/1.
      if (String.Compare(((TextBox)E.Item.Cells
         [numCols-1].Controls[0]).Text, "true", true)==0)
         myCommand.Parameters["@Contract"].Value =  "1"; 
      else
         myCommand.Parameters["@Contract"].Value =  "0"; 
         // Connect to the database and update the information.
         myCommand.Connection.Open();
         // Test  whether the data was updated and  display the 
         //appropriate message to the user.
         try 
         {
            myCommand.ExecuteNonQuery();
            Message.InnerHtml = "<b>Record Updated.</b><br>";
            MyDataGrid.EditItemIndex = -1;
         }
         catch (SqlException e) 
         {
            if (e.Number == 2627)
               Message.InnerHtml = "ERROR: A record already exists" +
                  " with the same primary key";
            else
               Message.InnerHtml = "ERROR: Could not update record," +
                 " please ensure the fields are correctly filled out";
               Message.Style["color"] = "red";
         }
      // Close the connection.
      myCommand.Connection.Close();
      // Show the updated information.
      BindGrid();
   }   // The BindGrid procedure connects to the database and implements
   // a SQL SELECT query to get all data in the "Authors" table.
   public void BindGrid() 
   {
      SqlConnection myConnection = new SqlConnection(
         "server=localhost;database=sx;Trusted_Connection=Yes");
      SqlDataAdapter myCommand = new SqlDataAdapter(
         "SELECT * FROM sx_teacher_info", myConnection);
      DataSet ds = new DataSet();
      myCommand.Fill(ds);
      MyDataGrid.DataSource=ds;
      MyDataGrid.DataBind();
   }
</script>
<%--  Display the data in the body of the page. --%>
<body style="FONT: 10pt verdana">
<form runat="server" ID="Form1">
<h3><font face="Verdana"> 金城江区实验小学教师个人信息表</font></h3>
<span id="Message" EnableViewState="false" runat="server" />
<p>
<ASP:DataGrid id="MyDataGrid" runat="server" Width="800" BackColor="#ccccff" BorderColor="black"
ShowFooter="false" CellPadding="3" CellSpacing="0" Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#aaaadd"
OnEditCommand="MyDataGrid_Edit" OnCancelCommand="MyDataGrid_Cancel" OnUpdateCommand="MyDataGrid_Update"
DataKeyField="sx_id">
<HeaderStyle BackColor="#AAAADD"></HeaderStyle>
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
</Columns>
</ASP:DataGrid>
</form>
</P>
</body>
</HTML>数据能正常显示,但updata时就抛出这个东东,要怎么解决。哪里有错啊,
ERROR: Could not update record, please ensure the fields are correctly filled out