Re: DataGrid problem.
From: Fred Hirschfeld (a_at_b.c)
Date: 08/21/04
- Next message: Fred Morin: "Updating textbox and underlying currentrow.column at the same time ?"
- Previous message: Miha Markic [MVP C#]: "Re: combobox data binding"
- In reply to: Integer Software: "Re: DataGrid problem."
- Next in thread: Integer Software: "Re: DataGrid problem."
- Reply: Integer Software: "Re: DataGrid problem."
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 21 Aug 2004 07:21:14 -0700
Can you post some more of the code around the creation of the SelectCommand
(and SQL) as well as the Insert and Update commands? I would expect that you
still need all columns of the PK in the Select to be able to properly let
the DataSet handle the records.
With more code I should be able to help.
Fred
"Integer Software" <usenet@fub-group.de> wrote in message
news:cg49pm$cet$07$1@news.t-online.com...
> Thanks for replying Fred,
> This is a WinForms app. Yes I managed to fix the original problem in the
way
> you described, by permitting nulls into the dataset.
>
> I can now fill the grid, and the only problem comes when updating, as in
the
> second post. The remaining column that causes a problem is the KTLFDN
> column, which is not a foreign key, but it does form a compound primary
key
> with KTADNO. That shouldnt be the issue however.
>
> And thats what is confusing me. Because I DO populate it in the code
snippet
> shown, why does update give an error message? It seems as though the
update
> doesnt look at the dataset at all, and prefers only to check the
> dataAdapters sql commands parameters Value field, or the column its bound
> to.
>
> What is the proper way to use update with datasets, when the parameter has
> no default value, and has no bound column, but is instead set manually in
> the dataset before the update.
>
> The only way I can think of is to manually work out if I need an update or
> an insert, and manually form the SQL command string myself with the
> parameters hard coded for each row, and call the sql commands rather than
> the update.
>
> But surely the whole idea of datasets and dataadapters is to make all this
> automagic.
>
> Its almost like something is missing from the OleDbParameter Collection
> Editor. We have options for setting a source column OR specifying a
> permanent value, but the most useful third option is missing, we need to
be
> able to specify that the value is to be taken simply from the dataset.
>
> Fred Hirschfeld wrote:
>
> > Is this Web or WinForms based? The reason that you are getting the first
> > message (in previous post) is that since you did not bind the extra
column
> > to the grid, it is automatically assigned a NULL value when a new row is
> > created.
> >
> > Now I am not sure this will work to solve the original problem, BUT
maybe
> > you could leave the column in the dataset not bound to the grid and just
> > modify the dataset structure to allow NULL in that column before binding
> > to the datagrid. If there are problems when updating, maybe also try to
> > reinstate the NULL rule after but before you do the update.
> >
> > If this is a FK field, isn't it going to be populated before the commit
> > happens (as in you second post)? Maybe the database structure has NOT
NULL
> > when it should allow NULL? Is there a default value that is to be placed
> > on this field?
> >
> > Fred
> >
> > "Integer Software" <usenet@fub-group.de> wrote in message
> > news:cg2mp4$eod$01$1@news.t-online.com...
> >> Hello. Does MSDN not entitle me to an answer here within a certain
amount
> > of
> >> time or is this not one of the managed newsgroups?
> >>
> >> Anyway, I have come a little further by taking ktadno out of the
dataset.
> > It
> >> should still get saved as ktadno is still present as a parameter in the
> >> Insert and Update statements of the DataAdapter. I can now at least
fill
> >> in my dataset from the grid without any errors.
> >>
> >> However when saving the dataset to the database I have a new error.
This
> > is
> >> what my saving code looks like:
> >>
> >> // Store record
> >> try
> >> {
> >> int biggest =0;
> >> foreach(DataRow dr in dsBankVerbindungen1.ktpfrec.Rows)
> >> {
> >> if (dr["KTLFDN"]!= DBNull.Value &&
> > Convert.ToInt16(dr["KTLFDN"]) >
> >> biggest)
> >> biggest = Convert.ToInt16(dr["KTLFDN"]);
> >> }
> >> foreach(DataRow dr in dsBankVerbindungen1.ktpfrec.Rows)
> >> {
> >> if (dr["KTLFDN"]==DBNull.Value)
> >> dr["KTLFDN"] = ++biggest;
> >> }
> >>
> >> oleDbDataAdapter7.Update(dsBankVerbindungen1);
> >> }
> >> catch(Exception ex)
> >> {
> >> MessageBox.Show(ex.Message);
> >> }
> >>
> >> Now I need to set this KTLFDN manually as its not required for the user
> >> to enter it in the datagrid, and indeed it is not even present in the
> >> datagrid. KTLFDN is a parameter in the DataAdapters Insert and Update
> >> statements, and the above code gives me the error "Parameter?_6 has no
> >> Standard Value" (thats a translation from the german error message).
And
> >> I get a Red circle with an exclamation mark next to the first row in
the
> >> datagrid.
> >>
> >> If I then take KTLFDN out of the Insert commands list of parameters,
the
> >> above code gives me the error "For at least one of the necessary
> >> Parameters, no value was given". And I get the exclamation mark.
> >>
> >> Now from the OleDbParameter Collection Editor, I see that most of my
> > fields
> >> are bound to columns in the DataGrid. KTADNO is set one time before the
> >> DataAdapter is used, since KTADNO is the same for every row in this
> >> instance of the DataGrid. But KTLFDN is different for each row in the
> >> dataset.
> >>
> >> How do I ensure that the parameter does not have a fixed value, and is
> >> not bound to a column, but instead gets its value from the dataset?
- Next message: Fred Morin: "Updating textbox and underlying currentrow.column at the same time ?"
- Previous message: Miha Markic [MVP C#]: "Re: combobox data binding"
- In reply to: Integer Software: "Re: DataGrid problem."
- Next in thread: Integer Software: "Re: DataGrid problem."
- Reply: Integer Software: "Re: DataGrid problem."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|