This is driving me crazy ...

I have a typed dataset that I created using VS2008. I created an Insert
statement:

"INSERT INTO x (v1, v2, v3, ..., vN) VALUES (?, ?, ?, ... N?)"

Then I add parameters to the Insert command (OleDbCommand BTW, going into an
Access database):

myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnName",
OleDbType.DBTimeStamp));
myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnName2",
OleDbType.Char));
...
myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnNameN",
OleDbType.UnsignedInt));

Now I set my default values:
myOldDbCommandInsert.Parameters["c1"].Value = defaultValue1;
myOldDbCommandInsert.Parameters["c2"].Value = defaultValue2;
...
myOldDbCommandInsert.Parameters["cN"].Value = defaultValueN;

Then I create my data adapter:
OleDbDataAdapter a = new OleDbDataAdapter("SELECT * FROM x", myConn);

Then the dataset:
MyCustomDataSet ds = new MyCustomDataSet();
a.Fill(ds.MyCustomTable);

So far, everything has worked fine up until this point. So now, I simply
want to add rows to MyCustomTable:
SomeLoopWith5ValuesOrWhatever
{
MyCustomDataSet.MyCustomRowA r = (cast)
MyCustomDataSet.MyCustomTable.NewRow();
r.v1 = x;
r.v2 = y;
r.v3 = z;
r.nN = N;
myDataSet.myDataTable.Rows.Add(r);
}

Stepping through the debugger, that appears to do exactly what I expect. I
can see that the table gets the new rows, and they have the correct values.

However, when I do the following:
myDataAdapter.Update(myDataSet, "NameOfCorrectTable");

The correct number of rows are added to the correct table, but they do not
have the new values?!! They are keeping the default values that I set
earlier in my code. Why is my INSERT statement using these default values?

It's been a while since I messed with database stuff.
Thanks.

Re: INSERT Problem by Cowboy

Cowboy
Fri May 09 08:23:18 CDT 2008

From a cursory glance, it appears you are not only setting up the statement,
but telling it what values to use. Without seeing the code in context, I
cannot be 100% certain, but Parameters are not generally set up as defaults,
if at all. What is happening is you are loading up new values then calling
Update. When Update is called, your explicit values for the parameters,
which you are calling defaults, are being called and overriding the values
you are inserting. If you get rid of the "defaults", I think you will find
one of two things:

1. It is saving correctly
2. You have exposed another error

Since I do not currently have the time to try to experiment through it, I
cannot be 100% sure I am on track, but I would guess I am hitting the nail
squarely on the head. :-)

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************
"Tom" <johnthompson1@hotmail.com> wrote in message
news:20948101-AFF6-473A-92C3-33DBAE8A20DE@microsoft.com...
> This is driving me crazy ...
>
> I have a typed dataset that I created using VS2008. I created an Insert
> statement:
>
> "INSERT INTO x (v1, v2, v3, ..., vN) VALUES (?, ?, ?, ... N?)"
>
> Then I add parameters to the Insert command (OleDbCommand BTW, going into
> an
> Access database):
>
> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnName",
> OleDbType.DBTimeStamp));
> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnName2",
> OleDbType.Char));
> ...
> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnNameN",
> OleDbType.UnsignedInt));
>
> Now I set my default values:
> myOldDbCommandInsert.Parameters["c1"].Value = defaultValue1;
> myOldDbCommandInsert.Parameters["c2"].Value = defaultValue2;
> ...
> myOldDbCommandInsert.Parameters["cN"].Value = defaultValueN;
>
> Then I create my data adapter:
> OleDbDataAdapter a = new OleDbDataAdapter("SELECT * FROM x", myConn);
>
> Then the dataset:
> MyCustomDataSet ds = new MyCustomDataSet();
> a.Fill(ds.MyCustomTable);
>
> So far, everything has worked fine up until this point. So now, I simply
> want to add rows to MyCustomTable:
> SomeLoopWith5ValuesOrWhatever
> {
> MyCustomDataSet.MyCustomRowA r = (cast)
> MyCustomDataSet.MyCustomTable.NewRow();
> r.v1 = x;
> r.v2 = y;
> r.v3 = z;
> r.nN = N;
> myDataSet.myDataTable.Rows.Add(r);
> }
>
> Stepping through the debugger, that appears to do exactly what I expect.
> I
> can see that the table gets the new rows, and they have the correct
> values.
>
> However, when I do the following:
> myDataAdapter.Update(myDataSet, "NameOfCorrectTable");
>
> The correct number of rows are added to the correct table, but they do not
> have the new values?!! They are keeping the default values that I set
> earlier in my code. Why is my INSERT statement using these default
> values?
>
> It's been a while since I messed with database stuff.
> Thanks.
>



Re: INSERT Problem by Tom

Tom
Fri May 09 08:31:25 CDT 2008

Greg, thanks for the quick response.

That does seem interesting. However, if I try it without my explicit
values:
/*
>> myOldDbCommandInsert.Parameters["c1"].Value = defaultValue1;
>> myOldDbCommandInsert.Parameters["c2"].Value = defaultValue2;
>> ...
>> myOldDbCommandInsert.Parameters["cN"].Value = defaultValueN;
*/

I get the following error when I try to update:
"Parameter ?_1 has no default value."

Any other ideas? I have no other idea what could possibly be wrong with my
code.

Thanks again.
-- Tom


"Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@comcast.netNoSpamM> wrote in
message news:OvsbefdsIHA.5068@TK2MSFTNGP02.phx.gbl...
> From a cursory glance, it appears you are not only setting up the
> statement, but telling it what values to use. Without seeing the code in
> context, I cannot be 100% certain, but Parameters are not generally set up
> as defaults, if at all. What is happening is you are loading up new values
> then calling Update. When Update is called, your explicit values for the
> parameters, which you are calling defaults, are being called and
> overriding the values you are inserting. If you get rid of the "defaults",
> I think you will find one of two things:
>
> 1. It is saving correctly
> 2. You have exposed another error
>
> Since I do not currently have the time to try to experiment through it, I
> cannot be 100% sure I am on track, but I would guess I am hitting the nail
> squarely on the head. :-)
>
> --
> Gregory A. Beamer
> MVP, MCP: +I, SE, SD, DBA
>
> Subscribe to my blog
> http://gregorybeamer.spaces.live.com/lists/feed.rss
>
> or just read it:
> http://gregorybeamer.spaces.live.com/
>
> *************************************************
> | Think outside the box! |
> *************************************************
> "Tom" <johnthompson1@hotmail.com> wrote in message
> news:20948101-AFF6-473A-92C3-33DBAE8A20DE@microsoft.com...
>> This is driving me crazy ...
>>
>> I have a typed dataset that I created using VS2008. I created an Insert
>> statement:
>>
>> "INSERT INTO x (v1, v2, v3, ..., vN) VALUES (?, ?, ?, ... N?)"
>>
>> Then I add parameters to the Insert command (OleDbCommand BTW, going into
>> an
>> Access database):
>>
>> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnName",
>> OleDbType.DBTimeStamp));
>> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnName2",
>> OleDbType.Char));
>> ...
>> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnNameN",
>> OleDbType.UnsignedInt));
>>
>> Now I set my default values:
>> myOldDbCommandInsert.Parameters["c1"].Value = defaultValue1;
>> myOldDbCommandInsert.Parameters["c2"].Value = defaultValue2;
>> ...
>> myOldDbCommandInsert.Parameters["cN"].Value = defaultValueN;
>>
>> Then I create my data adapter:
>> OleDbDataAdapter a = new OleDbDataAdapter("SELECT * FROM x", myConn);
>>
>> Then the dataset:
>> MyCustomDataSet ds = new MyCustomDataSet();
>> a.Fill(ds.MyCustomTable);
>>
>> So far, everything has worked fine up until this point. So now, I simply
>> want to add rows to MyCustomTable:
>> SomeLoopWith5ValuesOrWhatever
>> {
>> MyCustomDataSet.MyCustomRowA r = (cast)
>> MyCustomDataSet.MyCustomTable.NewRow();
>> r.v1 = x;
>> r.v2 = y;
>> r.v3 = z;
>> r.nN = N;
>> myDataSet.myDataTable.Rows.Add(r);
>> }
>>
>> Stepping through the debugger, that appears to do exactly what I expect.
>> I
>> can see that the table gets the new rows, and they have the correct
>> values.
>>
>> However, when I do the following:
>> myDataAdapter.Update(myDataSet, "NameOfCorrectTable");
>>
>> The correct number of rows are added to the correct table, but they do
>> not
>> have the new values?!! They are keeping the default values that I set
>> earlier in my code. Why is my INSERT statement using these default
>> values?
>>
>> It's been a while since I messed with database stuff.
>> Thanks.
>>
>
>


Re: INSERT Problem by KerryMoorman

KerryMoorman
Fri May 09 09:36:05 CDT 2008

Tom,

When you manually create the dataadapter's InsertCommand then you need to
provide parameters for each column of the datatable row being inserted.

Here is some information that may be helpful:

http://msdn.microsoft.com/en-us/library/30bys7z3(VS.80).aspx

http://forums.asp.net/t/1258663.aspx

http://www.codersource.net/csharp_adonet_tutorial_ed.html

Kerry Moorman


"Tom" wrote:

> Greg, thanks for the quick response.
>
> That does seem interesting. However, if I try it without my explicit
> values:
> /*
> >> myOldDbCommandInsert.Parameters["c1"].Value = defaultValue1;
> >> myOldDbCommandInsert.Parameters["c2"].Value = defaultValue2;
> >> ...
> >> myOldDbCommandInsert.Parameters["cN"].Value = defaultValueN;
> */
>
> I get the following error when I try to update:
> "Parameter ?_1 has no default value."
>
> Any other ideas? I have no other idea what could possibly be wrong with my
> code.
>
> Thanks again.
> -- Tom
>
>
> "Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@comcast.netNoSpamM> wrote in
> message news:OvsbefdsIHA.5068@TK2MSFTNGP02.phx.gbl...
> > From a cursory glance, it appears you are not only setting up the
> > statement, but telling it what values to use. Without seeing the code in
> > context, I cannot be 100% certain, but Parameters are not generally set up
> > as defaults, if at all. What is happening is you are loading up new values
> > then calling Update. When Update is called, your explicit values for the
> > parameters, which you are calling defaults, are being called and
> > overriding the values you are inserting. If you get rid of the "defaults",
> > I think you will find one of two things:
> >
> > 1. It is saving correctly
> > 2. You have exposed another error
> >
> > Since I do not currently have the time to try to experiment through it, I
> > cannot be 100% sure I am on track, but I would guess I am hitting the nail
> > squarely on the head. :-)
> >
> > --
> > Gregory A. Beamer
> > MVP, MCP: +I, SE, SD, DBA
> >
> > Subscribe to my blog
> > http://gregorybeamer.spaces.live.com/lists/feed.rss
> >
> > or just read it:
> > http://gregorybeamer.spaces.live.com/
> >
> > *************************************************
> > | Think outside the box! |
> > *************************************************
> > "Tom" <johnthompson1@hotmail.com> wrote in message
> > news:20948101-AFF6-473A-92C3-33DBAE8A20DE@microsoft.com...
> >> This is driving me crazy ...
> >>
> >> I have a typed dataset that I created using VS2008. I created an Insert
> >> statement:
> >>
> >> "INSERT INTO x (v1, v2, v3, ..., vN) VALUES (?, ?, ?, ... N?)"
> >>
> >> Then I add parameters to the Insert command (OleDbCommand BTW, going into
> >> an
> >> Access database):
> >>
> >> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnName",
> >> OleDbType.DBTimeStamp));
> >> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnName2",
> >> OleDbType.Char));
> >> ...
> >> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnNameN",
> >> OleDbType.UnsignedInt));
> >>
> >> Now I set my default values:
> >> myOldDbCommandInsert.Parameters["c1"].Value = defaultValue1;
> >> myOldDbCommandInsert.Parameters["c2"].Value = defaultValue2;
> >> ...
> >> myOldDbCommandInsert.Parameters["cN"].Value = defaultValueN;
> >>
> >> Then I create my data adapter:
> >> OleDbDataAdapter a = new OleDbDataAdapter("SELECT * FROM x", myConn);
> >>
> >> Then the dataset:
> >> MyCustomDataSet ds = new MyCustomDataSet();
> >> a.Fill(ds.MyCustomTable);
> >>
> >> So far, everything has worked fine up until this point. So now, I simply
> >> want to add rows to MyCustomTable:
> >> SomeLoopWith5ValuesOrWhatever
> >> {
> >> MyCustomDataSet.MyCustomRowA r = (cast)
> >> MyCustomDataSet.MyCustomTable.NewRow();
> >> r.v1 = x;
> >> r.v2 = y;
> >> r.v3 = z;
> >> r.nN = N;
> >> myDataSet.myDataTable.Rows.Add(r);
> >> }
> >>
> >> Stepping through the debugger, that appears to do exactly what I expect.
> >> I
> >> can see that the table gets the new rows, and they have the correct
> >> values.
> >>
> >> However, when I do the following:
> >> myDataAdapter.Update(myDataSet, "NameOfCorrectTable");
> >>
> >> The correct number of rows are added to the correct table, but they do
> >> not
> >> have the new values?!! They are keeping the default values that I set
> >> earlier in my code. Why is my INSERT statement using these default
> >> values?
> >>
> >> It's been a while since I messed with database stuff.
> >> Thanks.
> >>
> >
> >
>
>

Re: INSERT Problem by Tom

Tom
Fri May 09 10:09:03 CDT 2008

Well, I found out what my problem was. Thanks Kerry for the references.

It turns out the when I added parameters, I was doing it this way:
>> >> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnName",
>> >> OleDbType.DBTimeStamp));
>> >> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnName2",
>> >> OleDbType.Char));

However, I never got the value because I didn't specify the source column in
memory. If I add the parameters like this:
parameters.add("myColumnName", oleDbType, 0,
"SourceColumnNameWhichIsTheSameAsmyColumnName");

Everything works fine now. Thanks again.


"Kerry Moorman" <KerryMoorman@discussions.microsoft.com> wrote in message
news:DF43539D-5000-45CB-8D44-900AE840A56F@microsoft.com...
> Tom,
>
> When you manually create the dataadapter's InsertCommand then you need to
> provide parameters for each column of the datatable row being inserted.
>
> Here is some information that may be helpful:
>
> http://msdn.microsoft.com/en-us/library/30bys7z3(VS.80).aspx
>
> http://forums.asp.net/t/1258663.aspx
>
> http://www.codersource.net/csharp_adonet_tutorial_ed.html
>
> Kerry Moorman
>
>
> "Tom" wrote:
>
>> Greg, thanks for the quick response.
>>
>> That does seem interesting. However, if I try it without my explicit
>> values:
>> /*
>> >> myOldDbCommandInsert.Parameters["c1"].Value = defaultValue1;
>> >> myOldDbCommandInsert.Parameters["c2"].Value = defaultValue2;
>> >> ...
>> >> myOldDbCommandInsert.Parameters["cN"].Value = defaultValueN;
>> */
>>
>> I get the following error when I try to update:
>> "Parameter ?_1 has no default value."
>>
>> Any other ideas? I have no other idea what could possibly be wrong with
>> my
>> code.
>>
>> Thanks again.
>> -- Tom
>>
>>
>> "Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@comcast.netNoSpamM> wrote in
>> message news:OvsbefdsIHA.5068@TK2MSFTNGP02.phx.gbl...
>> > From a cursory glance, it appears you are not only setting up the
>> > statement, but telling it what values to use. Without seeing the code
>> > in
>> > context, I cannot be 100% certain, but Parameters are not generally set
>> > up
>> > as defaults, if at all. What is happening is you are loading up new
>> > values
>> > then calling Update. When Update is called, your explicit values for
>> > the
>> > parameters, which you are calling defaults, are being called and
>> > overriding the values you are inserting. If you get rid of the
>> > "defaults",
>> > I think you will find one of two things:
>> >
>> > 1. It is saving correctly
>> > 2. You have exposed another error
>> >
>> > Since I do not currently have the time to try to experiment through it,
>> > I
>> > cannot be 100% sure I am on track, but I would guess I am hitting the
>> > nail
>> > squarely on the head. :-)
>> >
>> > --
>> > Gregory A. Beamer
>> > MVP, MCP: +I, SE, SD, DBA
>> >
>> > Subscribe to my blog
>> > http://gregorybeamer.spaces.live.com/lists/feed.rss
>> >
>> > or just read it:
>> > http://gregorybeamer.spaces.live.com/
>> >
>> > *************************************************
>> > | Think outside the box! |
>> > *************************************************
>> > "Tom" <johnthompson1@hotmail.com> wrote in message
>> > news:20948101-AFF6-473A-92C3-33DBAE8A20DE@microsoft.com...
>> >> This is driving me crazy ...
>> >>
>> >> I have a typed dataset that I created using VS2008. I created an
>> >> Insert
>> >> statement:
>> >>
>> >> "INSERT INTO x (v1, v2, v3, ..., vN) VALUES (?, ?, ?, ... N?)"
>> >>
>> >> Then I add parameters to the Insert command (OleDbCommand BTW, going
>> >> into
>> >> an
>> >> Access database):
>> >>
>> >> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnName",
>> >> OleDbType.DBTimeStamp));
>> >> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnName2",
>> >> OleDbType.Char));
>> >> ...
>> >> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnNameN",
>> >> OleDbType.UnsignedInt));
>> >>
>> >> Now I set my default values:
>> >> myOldDbCommandInsert.Parameters["c1"].Value = defaultValue1;
>> >> myOldDbCommandInsert.Parameters["c2"].Value = defaultValue2;
>> >> ...
>> >> myOldDbCommandInsert.Parameters["cN"].Value = defaultValueN;
>> >>
>> >> Then I create my data adapter:
>> >> OleDbDataAdapter a = new OleDbDataAdapter("SELECT * FROM x", myConn);
>> >>
>> >> Then the dataset:
>> >> MyCustomDataSet ds = new MyCustomDataSet();
>> >> a.Fill(ds.MyCustomTable);
>> >>
>> >> So far, everything has worked fine up until this point. So now, I
>> >> simply
>> >> want to add rows to MyCustomTable:
>> >> SomeLoopWith5ValuesOrWhatever
>> >> {
>> >> MyCustomDataSet.MyCustomRowA r = (cast)
>> >> MyCustomDataSet.MyCustomTable.NewRow();
>> >> r.v1 = x;
>> >> r.v2 = y;
>> >> r.v3 = z;
>> >> r.nN = N;
>> >> myDataSet.myDataTable.Rows.Add(r);
>> >> }
>> >>
>> >> Stepping through the debugger, that appears to do exactly what I
>> >> expect.
>> >> I
>> >> can see that the table gets the new rows, and they have the correct
>> >> values.
>> >>
>> >> However, when I do the following:
>> >> myDataAdapter.Update(myDataSet, "NameOfCorrectTable");
>> >>
>> >> The correct number of rows are added to the correct table, but they do
>> >> not
>> >> have the new values?!! They are keeping the default values that I set
>> >> earlier in my code. Why is my INSERT statement using these default
>> >> values?
>> >>
>> >> It's been a while since I messed with database stuff.
>> >> Thanks.
>> >>
>> >
>> >
>>
>>


Re: INSERT Problem by Cowboy

Cowboy
Fri May 09 13:19:37 CDT 2008

I would have to see the code to get a better idea.

I would say AcceptChanges on the DS, but I think that is merely to be able
to grab things off a DataTable when you need to grab items back out, or
similar. Besides, I have never seen this type of behavior.

What you have told me here shows that the values of the rows are not being
sent to the command at all. I would still try the drag and drop approach and
try to refactor yours in the same way. You can be sure that will work.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************
"Tom" <johnthompson1@hotmail.com> wrote in message
news:%23dEoCkdsIHA.2068@TK2MSFTNGP05.phx.gbl...
> Greg, thanks for the quick response.
>
> That does seem interesting. However, if I try it without my explicit
> values:
> /*
>>> myOldDbCommandInsert.Parameters["c1"].Value = defaultValue1;
>>> myOldDbCommandInsert.Parameters["c2"].Value = defaultValue2;
>>> ...
>>> myOldDbCommandInsert.Parameters["cN"].Value = defaultValueN;
> */
>
> I get the following error when I try to update:
> "Parameter ?_1 has no default value."
>
> Any other ideas? I have no other idea what could possibly be wrong with
> my code.
>
> Thanks again.
> -- Tom
>
>
> "Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@comcast.netNoSpamM> wrote in
> message news:OvsbefdsIHA.5068@TK2MSFTNGP02.phx.gbl...
>> From a cursory glance, it appears you are not only setting up the
>> statement, but telling it what values to use. Without seeing the code in
>> context, I cannot be 100% certain, but Parameters are not generally set
>> up as defaults, if at all. What is happening is you are loading up new
>> values then calling Update. When Update is called, your explicit values
>> for the parameters, which you are calling defaults, are being called and
>> overriding the values you are inserting. If you get rid of the
>> "defaults", I think you will find one of two things:
>>
>> 1. It is saving correctly
>> 2. You have exposed another error
>>
>> Since I do not currently have the time to try to experiment through it, I
>> cannot be 100% sure I am on track, but I would guess I am hitting the
>> nail squarely on the head. :-)
>>
>> --
>> Gregory A. Beamer
>> MVP, MCP: +I, SE, SD, DBA
>>
>> Subscribe to my blog
>> http://gregorybeamer.spaces.live.com/lists/feed.rss
>>
>> or just read it:
>> http://gregorybeamer.spaces.live.com/
>>
>> *************************************************
>> | Think outside the box! |
>> *************************************************
>> "Tom" <johnthompson1@hotmail.com> wrote in message
>> news:20948101-AFF6-473A-92C3-33DBAE8A20DE@microsoft.com...
>>> This is driving me crazy ...
>>>
>>> I have a typed dataset that I created using VS2008. I created an Insert
>>> statement:
>>>
>>> "INSERT INTO x (v1, v2, v3, ..., vN) VALUES (?, ?, ?, ... N?)"
>>>
>>> Then I add parameters to the Insert command (OleDbCommand BTW, going
>>> into an
>>> Access database):
>>>
>>> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnName",
>>> OleDbType.DBTimeStamp));
>>> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnName2",
>>> OleDbType.Char));
>>> ...
>>> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnNameN",
>>> OleDbType.UnsignedInt));
>>>
>>> Now I set my default values:
>>> myOldDbCommandInsert.Parameters["c1"].Value = defaultValue1;
>>> myOldDbCommandInsert.Parameters["c2"].Value = defaultValue2;
>>> ...
>>> myOldDbCommandInsert.Parameters["cN"].Value = defaultValueN;
>>>
>>> Then I create my data adapter:
>>> OleDbDataAdapter a = new OleDbDataAdapter("SELECT * FROM x", myConn);
>>>
>>> Then the dataset:
>>> MyCustomDataSet ds = new MyCustomDataSet();
>>> a.Fill(ds.MyCustomTable);
>>>
>>> So far, everything has worked fine up until this point. So now, I
>>> simply
>>> want to add rows to MyCustomTable:
>>> SomeLoopWith5ValuesOrWhatever
>>> {
>>> MyCustomDataSet.MyCustomRowA r = (cast)
>>> MyCustomDataSet.MyCustomTable.NewRow();
>>> r.v1 = x;
>>> r.v2 = y;
>>> r.v3 = z;
>>> r.nN = N;
>>> myDataSet.myDataTable.Rows.Add(r);
>>> }
>>>
>>> Stepping through the debugger, that appears to do exactly what I expect.
>>> I
>>> can see that the table gets the new rows, and they have the correct
>>> values.
>>>
>>> However, when I do the following:
>>> myDataAdapter.Update(myDataSet, "NameOfCorrectTable");
>>>
>>> The correct number of rows are added to the correct table, but they do
>>> not
>>> have the new values?!! They are keeping the default values that I set
>>> earlier in my code. Why is my INSERT statement using these default
>>> values?
>>>
>>> It's been a while since I messed with database stuff.
>>> Thanks.
>>>
>>
>>
>



Re: INSERT Problem by Cowboy

Cowboy
Fri May 09 13:20:30 CDT 2008

Good catch. I have gotten away from DataSets in many apps, so it is easy for
me to miss that. Will have to file it away.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://gregorybeamer.spaces.live.com/lists/feed.rss

or just read it:
http://gregorybeamer.spaces.live.com/

*************************************************
| Think outside the box!
|
*************************************************
"Tom" <johnthompson1@hotmail.com> wrote in message
news:981F8F7D-C53D-4EAD-A1C0-3667772896BE@microsoft.com...
> Well, I found out what my problem was. Thanks Kerry for the references.
>
> It turns out the when I added parameters, I was doing it this way:
>>> >> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnName",
>>> >> OleDbType.DBTimeStamp));
>>> >> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnName2",
>>> >> OleDbType.Char));
>
> However, I never got the value because I didn't specify the source column
> in memory. If I add the parameters like this:
> parameters.add("myColumnName", oleDbType, 0,
> "SourceColumnNameWhichIsTheSameAsmyColumnName");
>
> Everything works fine now. Thanks again.
>
>
> "Kerry Moorman" <KerryMoorman@discussions.microsoft.com> wrote in message
> news:DF43539D-5000-45CB-8D44-900AE840A56F@microsoft.com...
>> Tom,
>>
>> When you manually create the dataadapter's InsertCommand then you need to
>> provide parameters for each column of the datatable row being inserted.
>>
>> Here is some information that may be helpful:
>>
>> http://msdn.microsoft.com/en-us/library/30bys7z3(VS.80).aspx
>>
>> http://forums.asp.net/t/1258663.aspx
>>
>> http://www.codersource.net/csharp_adonet_tutorial_ed.html
>>
>> Kerry Moorman
>>
>>
>> "Tom" wrote:
>>
>>> Greg, thanks for the quick response.
>>>
>>> That does seem interesting. However, if I try it without my explicit
>>> values:
>>> /*
>>> >> myOldDbCommandInsert.Parameters["c1"].Value = defaultValue1;
>>> >> myOldDbCommandInsert.Parameters["c2"].Value = defaultValue2;
>>> >> ...
>>> >> myOldDbCommandInsert.Parameters["cN"].Value = defaultValueN;
>>> */
>>>
>>> I get the following error when I try to update:
>>> "Parameter ?_1 has no default value."
>>>
>>> Any other ideas? I have no other idea what could possibly be wrong with
>>> my
>>> code.
>>>
>>> Thanks again.
>>> -- Tom
>>>
>>>
>>> "Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@comcast.netNoSpamM> wrote
>>> in
>>> message news:OvsbefdsIHA.5068@TK2MSFTNGP02.phx.gbl...
>>> > From a cursory glance, it appears you are not only setting up the
>>> > statement, but telling it what values to use. Without seeing the code
>>> > in
>>> > context, I cannot be 100% certain, but Parameters are not generally
>>> > set up
>>> > as defaults, if at all. What is happening is you are loading up new
>>> > values
>>> > then calling Update. When Update is called, your explicit values for
>>> > the
>>> > parameters, which you are calling defaults, are being called and
>>> > overriding the values you are inserting. If you get rid of the
>>> > "defaults",
>>> > I think you will find one of two things:
>>> >
>>> > 1. It is saving correctly
>>> > 2. You have exposed another error
>>> >
>>> > Since I do not currently have the time to try to experiment through
>>> > it, I
>>> > cannot be 100% sure I am on track, but I would guess I am hitting the
>>> > nail
>>> > squarely on the head. :-)
>>> >
>>> > --
>>> > Gregory A. Beamer
>>> > MVP, MCP: +I, SE, SD, DBA
>>> >
>>> > Subscribe to my blog
>>> > http://gregorybeamer.spaces.live.com/lists/feed.rss
>>> >
>>> > or just read it:
>>> > http://gregorybeamer.spaces.live.com/
>>> >
>>> > *************************************************
>>> > | Think outside the box! |
>>> > *************************************************
>>> > "Tom" <johnthompson1@hotmail.com> wrote in message
>>> > news:20948101-AFF6-473A-92C3-33DBAE8A20DE@microsoft.com...
>>> >> This is driving me crazy ...
>>> >>
>>> >> I have a typed dataset that I created using VS2008. I created an
>>> >> Insert
>>> >> statement:
>>> >>
>>> >> "INSERT INTO x (v1, v2, v3, ..., vN) VALUES (?, ?, ?, ... N?)"
>>> >>
>>> >> Then I add parameters to the Insert command (OleDbCommand BTW, going
>>> >> into
>>> >> an
>>> >> Access database):
>>> >>
>>> >> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnName",
>>> >> OleDbType.DBTimeStamp));
>>> >> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnName2",
>>> >> OleDbType.Char));
>>> >> ...
>>> >> myOldDbCommandInsert.Parameters.Add(new OleDbParameter("columnNameN",
>>> >> OleDbType.UnsignedInt));
>>> >>
>>> >> Now I set my default values:
>>> >> myOldDbCommandInsert.Parameters["c1"].Value = defaultValue1;
>>> >> myOldDbCommandInsert.Parameters["c2"].Value = defaultValue2;
>>> >> ...
>>> >> myOldDbCommandInsert.Parameters["cN"].Value = defaultValueN;
>>> >>
>>> >> Then I create my data adapter:
>>> >> OleDbDataAdapter a = new OleDbDataAdapter("SELECT * FROM x", myConn);
>>> >>
>>> >> Then the dataset:
>>> >> MyCustomDataSet ds = new MyCustomDataSet();
>>> >> a.Fill(ds.MyCustomTable);
>>> >>
>>> >> So far, everything has worked fine up until this point. So now, I
>>> >> simply
>>> >> want to add rows to MyCustomTable:
>>> >> SomeLoopWith5ValuesOrWhatever
>>> >> {
>>> >> MyCustomDataSet.MyCustomRowA r = (cast)
>>> >> MyCustomDataSet.MyCustomTable.NewRow();
>>> >> r.v1 = x;
>>> >> r.v2 = y;
>>> >> r.v3 = z;
>>> >> r.nN = N;
>>> >> myDataSet.myDataTable.Rows.Add(r);
>>> >> }
>>> >>
>>> >> Stepping through the debugger, that appears to do exactly what I
>>> >> expect.
>>> >> I
>>> >> can see that the table gets the new rows, and they have the correct
>>> >> values.
>>> >>
>>> >> However, when I do the following:
>>> >> myDataAdapter.Update(myDataSet, "NameOfCorrectTable");
>>> >>
>>> >> The correct number of rows are added to the correct table, but they
>>> >> do
>>> >> not
>>> >> have the new values?!! They are keeping the default values that I
>>> >> set
>>> >> earlier in my code. Why is my INSERT statement using these default
>>> >> values?
>>> >>
>>> >> It's been a while since I messed with database stuff.
>>> >> Thanks.
>>> >>
>>> >
>>> >
>>>
>>>
>