VS.NET wizard generated SqlDataAdapter

  • Thread starter Thread starter Cor Ligthert
  • Start date Start date
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

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
 
Francois,

As I often write in this newsgroups, I hate SQL so please ask the question
again in a new thread

:-)

Cor

Francois said:
Hi Cor,

The reason was that I must be pretty tired (or dumb) to have not seen that
one! The reason was indeed what you pointed out, the following line
this.sqlDataAdapter1.Update(dsGameRisk);

has to be replaced by
this.sqlDataAdapter1.Update(dsGameLiability);

It was just probably some sort of copy paste mistake I did inside my own
code ! Sorry for the inconvenience. And thanks a lot to you, Cor!

I have an aside question which is why the wizard generated SQL
UpdateCommand
is with all those @Original_X XX parameters. In short, why is the WHERE
clause like:

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);

instead of:

WHERE (gameId = @Original_gameId)

Is it to avoid the update to succeed if someone updates the row between
the
time the row is readed and cached in the DataSet and the time the updated
DataSet is pushed back in the DB? I try to understand but I cannot see any
other logic than that. Also why is VS.NET doing like that by default? Is
that how MS believe how all application should work?

Francois.

Cor Ligthert said:
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

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
 
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
 
Hi Cor,

The reason was that I must be pretty tired (or dumb) to have not seen that
one! The reason was indeed what you pointed out, the following line
this.sqlDataAdapter1.Update(dsGameRisk);

has to be replaced by
this.sqlDataAdapter1.Update(dsGameLiability);

It was just probably some sort of copy paste mistake I did inside my own
code ! Sorry for the inconvenience. And thanks a lot to you, Cor!

I have an aside question which is why the wizard generated SQL UpdateCommand
is with all those @Original_X XX parameters. In short, why is the WHERE
clause like:

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);

instead of:

WHERE (gameId = @Original_gameId)

Is it to avoid the update to succeed if someone updates the row between the
time the row is readed and cached in the DataSet and the time the updated
DataSet is pushed back in the DB? I try to understand but I cannot see any
other logic than that. Also why is VS.NET doing like that by default? Is
that how MS believe how all application should work?

Francois.

Cor Ligthert said:
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

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
 
Back
Top