[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

Inserting post data into a database - again

I know I can insert QueryString data into a database with the code:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectDownloads %>"
            InsertCommand="INSERT INTO [Downloads]
            ([company], [address],)
            VALUES (@company,  @address,">
</asp:SqlDataSource>

<InsertParameters>
                <asp:QueryStringParameter Name="company" QueryStringField=company Type="String" />
                <asp:QueryStringParameter Name="address" QueryStringField=address Type="String" />
</InsertParameters>

But is there an elegant way, like this,  to do the same thing with parameters that have been posted, instead of passed in a QueryString?

I know it's possible to do it with

<%            
            SqlDataSource1.InsertParameters.Add("company", Request.Form("company"))
            SqlDataSource1.InsertParameters.Add("address", Request.Form("address"))
           
            SqlDataSource1.Insert()
%>

and that works fine, but it seems that if Microsoft gave us something nice for QueryParameters to put between <InsertParamerter> and </InsertParameter> they might have done the same for posted parameters.  

Thanks for any thoughts.

steva
0
steva
Asked:
steva
  • 3
  • 2
1 Solution
 
Qaiser_Mehmood_MughalCommented:
Simple Set action of the page where you want to get the posted data, save your data in hidden fields on this page. then on the resultant page get the values using.
Request object.

Request["UserName"]


where "UserName" is the name of the hidden field in the calling page.

0
 
stevaAuthor Commented:
Could you include the markup that puts the data into the database?
0
 
RejojohnyCommented:
I am sorry, but I do not think I understood your issue compeltely....

do you mean you need something like this?
SqlDataSource1.InsertParameters.Add("company", Request.Querystring("company"))
or
SqlDataSource1.InsertParameters.Add("company", company.text)) .. here company is the textbox on the same form and you can access that when the page is submitted for "save"

or are you asking the user to enter values in one webpage and posting to second webpage and you want the details entered in the first webpage (company, address etc) to be saved by the code in the second webpage. If yes, you could just insert the record in the first webpage itself and then redirect to the second webpage .. or is there a functional requirement that you had to take this approach of saving in the second webpage?

Rejo
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
stevaAuthor Commented:
Rejojohny,

I'm trying to get away from setting the properties of the SqlDataSource1 object directly, as in

                      SqlDataSource1.InsertParameters.Add("company", Request.Querystring("company"))

For querystring parameters ASP.Net 2.0 lets us use the more elegant

<InsertParameters>
                <asp:QueryStringParameter Name="company" QueryStringField=company Type="String" />
                <asp:QueryStringParameter Name="address" QueryStringField=address Type="String" />
</InsertParameters>

instead of directly setting the parameters ourselves.  My question is:   Is there something similar we can use to insert parameters that are posted to us instead of passed to us  in a querystsring, maybe something like

<InsertParameters>
                <asp:RequestFormParameter Name="company" Request.Form("company") Type="String" />
                <asp:RequestFormParameter Name="address" Request.Form("address") Type="String" />
</InsertParameters>


steva
0
 
RejojohnyCommented:
yes, you can . .like this
<insertparameters>
            <asp:formparameter name="company" formfield="CompanyNameBox" />

but this value is from a control on the same form and not from the previous form.. you can strore the value into the session and this form can even take values from session .. but I would not advice using sessions for this requirement. .. the ones that are suported by insertparameter are
ControlParameter, CookieParameter, SessionParameter, ProfileParameter, and QueryStringParameter ... QueryStringParameter and CookieParameter classes are used to bind to values in the HttpRequest class (From MSDN)
0
 
stevaAuthor Commented:
Thanks for the information.  

steva
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now