UpdateCmd="update student set Sno=@Sno,Sname=@Sname,Sbirth=@Sbirth Where Sno=@Sno"是不是有问题

解决方案 »

  1.   

    changeupdate student set Sno=@Sno,Sname=@Sname,Sbirth=@Sbirth Where Sno=@Sno
    ===>
    update student set Sname=@Sname,Sbirth=@Sbirth Where Sno=@Sno
      

  2.   

    哦,好像是有问题,不过我如果想要同时修改Sno呢?
      

  3.   

    Sno也可以修改,不过要定义两个Parameters对应Sno,分别设置SourceVersion:
    update student set Sno=@newSno,Sname=@Sname,Sbirth=@Sbirth Where Sno=@oraSno
    放在where子句里的parameter要设置SourceVersion = DataRowVersion.Original
    要更新的那个值就用默认的就可以了
      

  4.   

    UpdateCmd="update student set Sno=@Sno,Sname=@Sname,Sbirth=@Sbirth Where Sno=@OldSno"
    UComm=new SQLCommand(UpdateCmd,objConnection) UComm.Parameters.Add(New SqlParameter("@Sno", SqlDbType.VarChar))
    UComm.Parameters.Add(New SqlParameter("@Sname", SqlDbType.VarChar))
    UComm.Parameters.Add(New SqlParameter("@Sbirth", SqlDbType.VarChar))
    UComm.Parameters.Add(New SqlParameter("@OldSno", SqlDbType.VarChar))
    ....
    UComm.Parameters("@OldSno").Value = _
    StuData.DataKeys(CInt(e.Item.ItemIndex))
    ....
      

  5.   

    The following code example defines an UPDATE statement in which the CustomerID column is used as a SourceColumn for two parameters: @CustomerID (SET CustomerID = @CustomerID), and @OldCustomerID (WHERE CustomerID = @OldCustomerID). The @CustomerID parameter is used to update the CustomerID column to the current value in the DataRow. As a result, the CustomerID SourceColumn with a SourceVersion of Current is used. The @OldCustomerID parameter is used to identify the current row in the data source. Because the matching column value is found in the Original version of the row, the same SourceColumn (CustomerID) with a SourceVersion of Original is used.string updateSQL = "UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName WHERE CustomerID = @OldCustomerID";custDA.UpdateCommand.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID");custDA.UpdateCommand.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName");SqlParameter myParm = custDA.UpdateCommand.Parameters.Add("@OldCustomerID", SqlDbType.NChar, 5, "CustomerID");
    myParm.SourceVersion = DataRowVersion.Original;MSDN上的例子
      

  6.   

    sorry, didn't see lbx1979(Love Arsenal)'s post, his solution is better
      

  7.   

    lbx1979(Love Arsenal):
    custDA?What's that?a SQLCommand?Thank all of you VERY MUCH!
    I'll pay the points now!
      

  8.   

    custDA is a SqlDataAdapter