兄弟忙了一天了,不能解决的问题,各位大哥帮帮忙
以下是存储过程,这肯定没问题的:
------------------------------------------------
-- UpdateCustomer
------------------------------------------------
ALTER PROCEDURE UpdateCustomer
@custID NVARCHAR(5) = NULL,
@CoName NVARCHAR(40) = NULL,
@ContName NVARCHAR(30) = NULL,
@ContTitle NVARCHAR(30) = NULL
AS
SET XACT_ABORT ON
BEGIN TRANSACTION
-- Update customers table with new customer info
UPDATE Customers
SET CompanyName = @CoName,
ContactName = @ContName,
ContactTitle = @ContTitle
WHERE CustomerID = @custID
COMMIT TRANSACTION
RETURN 0
------------------------------------------------
以下是我要更新的代码(运行能通过,数据库(Northwind)里的数据就是不能更新,),我的QQ是:66520267,MSN:liyingsc@hotmail.com
public class DataAccess
{
private const String PKID_PARM = "@custID";
private const String CONAME_PARM = "@CoName";
private const String ContName = "@ContName";
private const String ContTitle = "@ContTitle";
private SqlDataAdapter dsCommand;
private SqlCommand updateCommand;
private string ConnectionString="data source=GZLLY;initial catalog=Northwind;user id=sa;workstation id=GZLLY";
public DataAccess()
{
dsCommand=new SqlDataAdapter();
}
public bool UpdateCustomer(DataSet ds)
{
dsCommand.UpdateCommand = GetUpdateCommand();
dsCommand.Update(ds,"customers");
//
if ( ds.HasErrors )
{
return false;
}
else
{
return true;
}
}
private SqlCommand GetUpdateCommand()
{
if ( updateCommand == null )
{
//
updateCommand = new SqlCommand("UpdateCustomer",new SqlConnection(ConnectionString));
updateCommand.CommandType = CommandType.StoredProcedure;
SqlParameterCollection sqlParams = updateCommand.Parameters;
sqlParams.Add(new SqlParameter(PKID_PARM, SqlDbType.NVarChar ,5));
sqlParams.Add(new SqlParameter(CONAME_PARM, SqlDbType.NVarChar, 40));
sqlParams.Add(new SqlParameter(ContName, SqlDbType.NVarChar, 30));
sqlParams.Add(new SqlParameter(ContTitle, SqlDbType.NVarChar, 30));
// Define the parameter mappings from the data table in the
sqlParams[PKID_PARM].SourceColumn ="CustomerID";
sqlParams[CONAME_PARM].SourceColumn ="CompanyName";
sqlParams[ContName].SourceColumn ="ContactName";
sqlParams[ContTitle].SourceColumn ="ContactTitle";
}
return updateCommand;
}
}