Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Insert values into DataSource.DataView programmatically??

Reply
Thread Tools

Insert values into DataSource.DataView programmatically??

 
 
TenDot
Guest
Posts: n/a
 
      07-08-2006
I'm using a wizard to collect data that will go into multiple tables. each
Wizstep has a separate DataSource object. When the Complete wizstep is
reached I want to update all the datasources with a common value in a column.
That key will not be know till the user saves.

I've tried:

SqlDataSource theSrce = (SqlDataSource)sSrces.Current;
DataView dv =
(DataView)theSrce.Select(DataSourceSelectArguments .Empty);
dv[0].BeginEdit();
dv[0]["FK_MedRec"] = 1;//
(int)HttpContext.Current.Session["MedRecId"];
dv[0]["FK_Pat"] =
1;//(int)HttpContext.Current.Session["MedRecId"];
dv[0].EndEdit();
theSrce.Insert();

I get access to dv[0] but everytime I try to insert I get an error tellling
me that dv[0]["FK_Pat"] is null (which is a constraint).

Am I doing something wrong?

TIA
--
TenDot
 
Reply With Quote
 
 
 
 
TenDot
Guest
Posts: n/a
 
      07-08-2006
OK, I got it...

here's the code:

SqlDataSource theSrce = (SqlDataSource)sSrces.Current;
theSrce.InsertParameters["FK_Pat"].DefaultValue = "1";
theSrce.InsertParameters["FK_MedRec"].DefaultValue =
medRecId.ToString();
theSrce.Insert();

it's' not in the DataView, you make the changes to the InsertParameters.
It's kind of wierd since you can't access the parameter value directly. My
sense is that DefaultValue only performs an assignment if it's null. I guess
that's ok.


--
TenDot


"TenDot" wrote:

> I'm using a wizard to collect data that will go into multiple tables. each
> Wizstep has a separate DataSource object. When the Complete wizstep is
> reached I want to update all the datasources with a common value in a column.
> That key will not be know till the user saves.
>
> I've tried:
>
> SqlDataSource theSrce = (SqlDataSource)sSrces.Current;
> DataView dv =
> (DataView)theSrce.Select(DataSourceSelectArguments .Empty);
> dv[0].BeginEdit();
> dv[0]["FK_MedRec"] = 1;//
> (int)HttpContext.Current.Session["MedRecId"];
> dv[0]["FK_Pat"] =
> 1;//(int)HttpContext.Current.Session["MedRecId"];
> dv[0].EndEdit();
> theSrce.Insert();
>
> I get access to dv[0] but everytime I try to insert I get an error tellling
> me that dv[0]["FK_Pat"] is null (which is a constraint).
>
> Am I doing something wrong?
>
> TIA
> --
> TenDot

 
Reply With Quote
 
 
 
 
TenDot
Guest
Posts: n/a
 
      07-09-2006
I spoke too soon...

Yeah I got the keys in there but somehow, the entered data is NOT there when
the record is written to the table??

Seems like I have to find the command to bind the data in the page controls
to the DataSource. Can I do that if I'm handling the DataSource controls in
a App_Code class??

Any thoughts??

Thanks
--
TenDot


"TenDot" wrote:

> OK, I got it...
>
> here's the code:
>
> SqlDataSource theSrce = (SqlDataSource)sSrces.Current;
> theSrce.InsertParameters["FK_Pat"].DefaultValue = "1";
> theSrce.InsertParameters["FK_MedRec"].DefaultValue =
> medRecId.ToString();
> theSrce.Insert();
>
> it's' not in the DataView, you make the changes to the InsertParameters.
> It's kind of wierd since you can't access the parameter value directly. My
> sense is that DefaultValue only performs an assignment if it's null. I guess
> that's ok.
>
>
> --
> TenDot
>
>
> "TenDot" wrote:
>
> > I'm using a wizard to collect data that will go into multiple tables. each
> > Wizstep has a separate DataSource object. When the Complete wizstep is
> > reached I want to update all the datasources with a common value in a column.
> > That key will not be know till the user saves.
> >
> > I've tried:
> >
> > SqlDataSource theSrce = (SqlDataSource)sSrces.Current;
> > DataView dv =
> > (DataView)theSrce.Select(DataSourceSelectArguments .Empty);
> > dv[0].BeginEdit();
> > dv[0]["FK_MedRec"] = 1;//
> > (int)HttpContext.Current.Session["MedRecId"];
> > dv[0]["FK_Pat"] =
> > 1;//(int)HttpContext.Current.Session["MedRecId"];
> > dv[0].EndEdit();
> > theSrce.Insert();
> >
> > I get access to dv[0] but everytime I try to insert I get an error tellling
> > me that dv[0]["FK_Pat"] is null (which is a constraint).
> >
> > Am I doing something wrong?
> >
> > TIA
> > --
> > TenDot

 
Reply With Quote
 
TenDot
Guest
Posts: n/a
 
      07-11-2006
Hi,

I'm still hacking at this problem. I've approached it from several angles
and still get get this done.

To recap:

I'm using a wizard to provide navigation through multiple data entry pages.
Each page is a separate table in a sql database. Each entry screen is a
FormView that's built as an ascx, which is dropped into the wizardstep.

When the Complete page is reached, I've put a button to do the update. The
update button calls code in the App_Code folder. The update method takes the
Page as a parameter and recursively searches the wiz pages for sqlDataSources
with a certain prefix and creates a list which it returns to the caller. The
caller then passes the list of sqlDatasources to an update method which loops
through the SqlDataSources. For each SqlDataSource 2 additional fields are
populated into the DataSource's Parameters and then performs the Insert() on
the data source.

What's actually happening is that the Data tables (all 10 of them) ARE being
inserted BUT only the last 2 fields that I've insertd values for, are getting
written to the table, all the user inserted data is being left behind and
show up null in the database. I know that this is happening because one of
the values that I write into the table is an integer that's incremented each
time I run a test.

I've taken the approach that there needs to be a DataBind() executed. I
tried that on the SqlDataSource, on the parent ascx and on the FormView each
in different iterations of the code. Nothing seems to work. I've also put
an OnInserting call back and can see the data in the Ascx textbox fields as
the user entered it while the Insert is in progress.

It seems like the goal is to update the InsertParameters but it seems kind
of dorky to update those manually (though I'm considering it at this point
).

Here's an example of the insert code.



while( sSrces.MoveNext() )
{
SqlDataSource theSrce = (SqlDataSource)sSrces.Current;
foreach (Control ctrl in theSrce.Parent.Controls)
{
if (ctrl.GetType() == typeof(FormView))
{
ctrl.DataBind();
}
}

theSrce.InsertParameters["FK_Pat"].DefaultValue =
PK_Pat.ToString();
theSrce.InsertParameters["FK_MedRec"].DefaultValue =
medRecId.ToString();

// I've also tried theSrce.DataBind();

theSrce.Insert();
}

I've tried everything I can think of. Any ideas?

Thanks
--
TenDot


"TenDot" wrote:

> I'm using a wizard to collect data that will go into multiple tables. each
> Wizstep has a separate DataSource object. When the Complete wizstep is
> reached I want to update all the datasources with a common value in a column.
> That key will not be know till the user saves.
>
> I've tried:
>
> SqlDataSource theSrce = (SqlDataSource)sSrces.Current;
> DataView dv =
> (DataView)theSrce.Select(DataSourceSelectArguments .Empty);
> dv[0].BeginEdit();
> dv[0]["FK_MedRec"] = 1;//
> (int)HttpContext.Current.Session["MedRecId"];
> dv[0]["FK_Pat"] =
> 1;//(int)HttpContext.Current.Session["MedRecId"];
> dv[0].EndEdit();
> theSrce.Insert();
>
> I get access to dv[0] but everytime I try to insert I get an error tellling
> me that dv[0]["FK_Pat"] is null (which is a constraint).
>
> Am I doing something wrong?
>
> TIA
> --
> TenDot

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to insert database values into a pdf sarellaravi@gmail.com ASP .Net 1 05-31-2007 09:15 AM
how to insert database values into a pdf katta.naveenkumar@gmail.com ASP .Net 1 05-31-2007 09:15 AM
insert values into databse using sqlserverstoredprocedure with asp.net Sirisha ASP .Net 1 02-20-2007 09:09 AM
How To Insert Code With Javascript, How to insert into a div an amountof code Sergio del Amo Javascript 4 05-29-2005 02:45 AM
Newbie :: WebMatrix - Insert Form Values into Db ASP .Net 0 03-16-2005 07:42 PM



Advertisments