I'm trying to create a formview bound to a sqldatasource, and use a
stored procedure to insert data from the formview into several tables.
I have some simplified code below, the real code is much longer but
this should illustrate the problem:
<asp:FormView ID="bookFormVie w" runat="server"
DataSourceID="b ookSqlDataSourc e">
<ItemTemplate >
<asp:textBox id="name"
text='<%# Eval("name") %>'
runat="server" />
<asp:textbox id="city"
text='<%#Eval(" city") %>'
</ItemTemplate>
<InsertItemTemp late>
<asp:textBox id="name"
text='<%# Bind("name") %>'
runat="server" />
<asp:textbox id="city"
text='<%#Bind(" city") %>'
runat = "server" />
</InsertItemTempl ate>
</asp:FormView>
<asp:SqlDataSou rce ID="bookSqlData Source" runat="server"
ConnectionStrin g="<%$
ConnectionStrin gs:lapubsDBConn ectionString %>"
ProviderName="< %$
ConnectionStrin gs:lapubsDBConn ectionString.Pr oviderName %>"
InsertCommandTy pe="StoredProce dure"
InsertCommand=" usp_add_person"
SelectCommand=" select name, city from view_namecity" >
<InsertParamete rs>
<asp:ControlPar ameter Name="Name" ControlID="???"
PropertyName="T ext" Type="String" ConvertEmptyStr ingToNull="TRUE "
Size="20" />
<asp:ControlPar ameter Name="City" ControlID="???"
PropertyName="T ext" Type="String" ConvertEmptyStr ingToNull="TRUE "
Size="20" />
</InsertParameter s>
</asp:SqlDataSour ce>
The problem I'm having is in what to specify in the ControlID attribute
of the SQLdatasource's insertParameter . It seems that the only object
it will recognize is the Formview (ie. ControlID="book FormView"). But
that isn't specifically the control that the param should be bound to.
But it doesn't understand if I specify ControlID="name " -- I think
that's because the page doesn't have such a control, the control is
embedded in the insertTemplate of the FormView. I've even tried
something like ControlID="book Formview.FindCo ntrol('name')" but that
doesn't work either. How can I get a handle for the control that's
embedded inside the formview's template?
Or am I approaching this the wrong way? Should I specify the parameter
list inside the insertCommand: insertCommand=" usp_add_person @name,
@city"? I can't really do that either because a couple of the
parameters are coming in from session and application variables, not
from the formview at all. I have to use a stored procedure because I
need to insert into multiple tables, and the app design won't allow me
to use triggers either.
Thanks, I hope someone can understand this question and has some
experience with this!
-- Ned 2 9898
Ned,
You simply need to use the Bind() method when binding any of your
fields to the FormView and then when you Insert or Update it will
automatically read the new values into your parameters. Use the
regular <asp:Paramete r /to fill the values from the FormView, and
<asp:SessionPar ameter /to fill from session variables.
To make things easy on yourself, make sure all of your parameter names
match from your stored proc, to your parameter variables in your
SqlDataSource, to your FormView.
This should allow everything to just work. It is really pretty nice,
once you get used to it.
One more thing you might run into if you use Guids in your database.
There is currently a bug when it comes to passing Guids throught he
<asp:Paramete r /variable. The wizard will default the type="object"
but you will want to just delete that and leave the type out and
everything will work.
Also, you should be able to use the FormView wizard to configure all of
this.
HTH,
Chris
Chris,
Sorry for the late reply and thanks for your help -- this did work. I
was making it more complicated than it was. I assumed a control inside
a formview was a control, so was trying to use a controlParamete r
instead of just a Parameter. At the moment I am not using GUIDs but I
may modify the code to use them.
Thanks again.
-- Ned
chris wrote:
Ned,
You simply need to use the Bind() method when binding any of your
fields to the FormView and then when you Insert or Update it will
automatically read the new values into your parameters. Use the
regular <asp:Paramete r /to fill the values from the FormView, and
<asp:SessionPar ameter /to fill from session variables.
To make things easy on yourself, make sure all of your parameter names
match from your stored proc, to your parameter variables in your
SqlDataSource, to your FormView.
This should allow everything to just work. It is really pretty nice,
once you get used to it.
One more thing you might run into if you use Guids in your database.
There is currently a bug when it comes to passing Guids throught he
<asp:Paramete r /variable. The wizard will default the type="object"
but you will want to just delete that and leave the type out and
everything will work.
Also, you should be able to use the FormView wizard to configure all of
this.
HTH,
Chris
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: pete |
last post by:
I seem unable to get the FormView with the SqlDataSource control in ASP.NET
2.0 beta 2 to insert into my MySQL 4.11 database corectly. When I run the
page and click on the Insert link a SQL insert happens and a record gets
inserted into my MySQL table but every field that is inserted is NULL.
I have a feeling it I am referancing the values incorrectly with my
InsertCommand. Here is the insert command:
InsertCommand="insert into...
|
by: sck10 |
last post by:
Hello,
I am creating a form for users to enter information about a lab and the
members of the lab. I have one form (FormView) that they use to enter
information about that lab. The keyvalue is "LabLocation_ID". With an
existing lab, they then need to add the members for that lab. So, what I am
trying to do is the following. With the FormView of the Lab open, the user
will click a button to open a FormView (InsertMode) and add a new...
|
by: Metal2You |
last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that
accesses a Sybase database back end. We're using Sybase SQL Anywhere
9.0.2.3228. I have installed and registered the Sybase .NET 2.0
DataProvider (iAnywhere.Data.AsaClient.dll) into the GAC so it can be
used in the ProviderName property of a SQLDataSource and loads properly
at run time.
The application I'm writing is a bit more complex than the example I'm
about to...
|
by: nate |
last post by:
the error returned is this:
Server Error in '/AnnAccRpt' Application.
--------------------------------------------------------------------------------
Could not find control 'DropDownList1' in ControlParameter 'DropDownList1'.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
|
by: Marcial |
last post by:
Greetings all!
After a week of toiling I've finallay decided to post the code below with
hopes that someone can point out my error(s).
Basically I have a Gridview/Formview on a ASP.NEt 2.0 page.
When I select a record on the Gridview I'm presented with the corresponding
FormView Template for Editing. Works fine!
ItemTemplate in FormView works fine...Edit button takes me Edit Template!
| |
by: davidgreen24 |
last post by:
Suppose I have a SQLDataSource object that returns 20 rows. I have a
FormView object bound to this control. Now when I click a hyperlink
(with querystring param called productID) I want the row with Product
ID="3765" (using this as an example) to be the one displayed in a
FormView Control. If I modify my SQLDataSource object to have a WHERE
clause (e.g. WHERE Product ID=...) then the SQLDataSource only returns
one record and I've lost my...
|
by: YMPN |
last post by:
Hi Everyone,
I'm deen from Riyadh.
Please do help me with some problem i have. I have this formview
control setup to recieved inputs from user (textbox, dropdownlist,
others).
After inserting, I want to send the data via email, the problem is how
do I do that?
|
by: LiamLiamLiam |
last post by:
G'day all.
I having a problem with my formview. I'll ty to explain my situation as best as i can.
I have a page with a search field at the top which is just a simple asp:textbox. Below that i have a gridview which displays the results of the search. if no search is entered, then the gridview shows all records. Below the gridview i have a formview for inserting and editing the records. when a user clicks on one of the records in the...
|
by: Cirene |
last post by:
I have a formview that is calling a stored procedure (thru an sqldatasource)
to update 2 tables. When I execute the update it runs fine, with no errors.
But the data does NOT change. Any ideas why?
Here's the stored proc, the datasource and the edit template of the
formview...
***************STORED PROC*******************
ALTER PROCEDURE dbo.UpdateCompanyUsers
(
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |