C
Cor Ligthert
Francois,
Any reasons you are doing everything with the dataset dsGameLiability and
update the dsGameRisk
(it is probaly not impossible to do it that way, however it looks for me
strange)
Cor
Any reasons you are doing everything with the dataset dsGameLiability and
update the dsGameRisk
(it is probaly not impossible to do it that way, however it looks for me
strange)
Cor
Francois said:Hi all,
I think i am in front of a simple problem but as I am a beginner I cannot
solve it.
I am using a wizard generated SqlDataAdapter. It generates for me all the
Sqlcommand and also a stronged typed dataset. The SqlDataAdapter is basic
and mapped to only 1 table in my DB. That table contains 4 fields + 1 PK.
I try to update a record in the DB through the dataset and the
sqlDataAdpater but it does not work and i really wonder why... Can someone
help me? I will give all the code details + table structure, even it is a
little bit lenghty but I think that it can help u to tell me what is the
problem
the DB table is the following:
CREATE TABLE [dbo].[gameLiability] (
[gameId] [int] NOT NULL ,
[AHHomeTeamLiability] [float] NULL ,
[AHAwayTeamLiability] [float] NULL ,
[AHLiveHomeTeamLiability] [float] NULL ,
[AHLiveAwayTeamLiability] [float] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[gameLiability] WITH NOCHECK ADD
CONSTRAINT [PK_gameLiability_1] PRIMARY KEY CLUSTERED
(
[gameId]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[gameLiability] ADD
CONSTRAINT [DF_gameLiability_AHHomeTeamLiability] DEFAULT (0) FOR
[AHHomeTeamLiability],
CONSTRAINT [DF_gameLiability_AHAwayTeamLiability] DEFAULT (0) FOR
[AHAwayTeamLiability],
CONSTRAINT [DF_gameLiability_AHLiveHomeTeamLiability] DEFAULT (0) FOR
[AHLiveHomeTeamLiability],
CONSTRAINT [DF_gameLiability_AHLiveAwayTeamLiability] DEFAULT (0) FOR
[AHLiveAwayTeamLiability]
GO
The generated SqlCommand with its parameter are the followings
this.sqlUpdateCommand1.CommandText =
@"UPDATE gameLiability SET gameId = @gameId, AHHomeTeamLiability =
@AHHomeTeamLiability,
AHAwayTeamLiability = @AHAwayTeamLiability, AHLiveHomeTeamLiability =
@AHLiveHomeTeamLiability,
AHLiveAwayTeamLiability = @AHLiveAwayTeamLiability
WHERE (gameId = @Original_gameId)
AND (AHAwayTeamLiability = @Original_AHAwayTeamLiability OR
@Original_AHAwayTeamLiability IS NULL AND AHAwayTeamLiability IS NULL)
AND (AHHomeTeamLiability = @Original_AHHomeTeamLiability OR
@Original_AHHomeTeamLiability IS NULL AND AHHomeTeamLiability IS NULL)
AND (AHLiveAwayTeamLiability = @Original_AHLiveAwayTeamLiability OR
@Original_AHLiveAwayTeamLiability IS NULL AND AHLiveAwayTeamLiability IS
NULL)
AND (AHLiveHomeTeamLiability = @Original_AHLiveHomeTeamLiability OR
@Original_AHLiveHomeTeamLiability IS NULL AND AHLiveHomeTeamLiability IS
NULL);
SELECT gameId, AHHomeTeamLiability, AHAwayTeamLiability,
AHLiveHomeTeamLiability, AHLiveAwayTeamLiability
FROM gameLiability WHERE (gameId = @gameId)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new SqlParameter("@gameId",
SqlDbType.Int, 4, "gameId"));
this.sqlUpdateCommand1.Parameters.Add(new
SqlParameter("@AHHomeTeamLiability", Float, 8, "AHHomeTeamLiability"));
this.sqlUpdateCommand1.Parameters.Add(new
SqlParameter("@AHAwayTeamLiability", Float, 8, "AHAwayTeamLiability"));
this.sqlUpdateCommand1.Parameters.Add(new
SqlParameter("@AHLiveHomeTeamLiability", Float, 8,
"AHLiveHomeTeamLiability"));
this.sqlUpdateCommand1.Parameters.Add(new
SqlParameter("@AHLiveAwayTeamLiability", Float, 8,
"AHLiveAwayTeamLiability"));
this.sqlUpdateCommand1.Parameters.Add(new SqlParameter("@Original_gameId",
Int, 4, ParameterDirection.Input, false, ((System.Byte)(0)),
((System.Byte)(0)), "gameId", DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new
SqlParameter("@Original_AHAwayTeamLiability", SqlDbType.Float, 8,
ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)),
"AHAwayTeamLiability", DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new
SqlParameter("@Original_AHHomeTeamLiability", SqlDbType.Float, 8,
ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)),
"AHHomeTeamLiability", DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new
SqlParameter("@Original_AHLiveAwayTeamLiability", SqlDbType.Float, 8,
ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)),
"AHLiveAwayTeamLiability", DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new
SqlParameter("@Original_AHLiveHomeTeamLiability", SqlDbType.Float, 8,
ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)),
"AHLiveHomeTeamLiability", DataRowVersion.Original, null));
Note that there are loads of @Original_XXXX parameters created.
Now my code snippet:
public void UpdateAsianGameLiability(decimal Amt, int GameID)
{
// populate the strongly typed dataset, basically, just call the Fill
method on the generated SqlDataAdapter
tdsGameLiability dsGameLiability = this.GetGameLiability(GameID, Conn1,
Txn);
// modify a field in the DataSet
dsGameLiability.gameLiability[0].AHHomeTeamLiability += (double) Amt;
// call the sqlDataAdapter update method
this.sqlDataAdapter1.Update(dsGameRisk);
}
pretty simple. Note that when i debug i see that the collection of
parameters belgonging the the updateCommand have their Value properties
all
set to null. But I assume that the Update method should get the parameter
values from the dataset isn't it? But it seems to not happen.
What am I doing wrong?
Tx a lot,
best regards,
Francois