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.
>>> >>
>>> >
>>> >
>>>
>>>
>