Showing posts with label sqldatasource. Show all posts
Showing posts with label sqldatasource. Show all posts

Monday, March 12, 2012

problem modifying sqldatasource for dropdownlist control

i use asp.net 2.0 and c#

initially the dropdownlist control is bound to the queryA ("select * from tableA".) for sqldatasource1

now in a button click event, i want to change the query to queryB ("select * from tableA where id = @.id".)

in the code below, i can change the SELECT query of sqldatasource1 from queryA to queryB, but how can i give value to the parameter? please help

protected

void Button1_Click(object sender,EventArgs e)

{

sqldatasource1.SelectCommand = queryB

}

You almost had it, you just needed to add a parameter to the SelectParameters collection like so:

ASPX

<asp:dropdownlist id="ddlProducts" runat="server" datasourceid="sdsProducts" datatextfield="ProductName"datavaluefield="ProductID" /><asp:sqldatasource id="sdsProducts" runat="server" connectionstring="<%$ ConnectionStrings:NorthwindConnectionString%>"selectcommand="SELECT Products.* FROM Products" /><br /><br /><asp:button id="btnSubmit" runat="server" onclick="btnSubmit_Click" text="Load DropDownList with Seafood products only" />

CODE-BEHIND

protected void btnSubmit_Click(object sender, EventArgs e){sdsProducts.SelectCommand ="SELECT * FROM Products WHERE CategoryID = @.CategoryID";sdsProducts.SelectParameters.Add("CategoryID","8");}

|||hi ecbruk, there is an error saying parameter already exist, please chose a different name ;(|||Are you already setting forth your parameter declaratively within you SqlDataSource?

Monday, February 20, 2012

Problem inserting calculated data using sqldatasource, PLEASE HELP....!

Hi, I have created a website and I have a web form, I need to capture data and calculate fields and then insert the calculated field including the data into a sqlserver database. I created a store procedure and the parameters for the txt boxes is working fine. But the calculated fieldds are not getting inserted. Can someone please help? the code for insert is below: For the calculated field, I used txtboxes which "hold" the calculated field in the submit button event. I also tried using query string field

like this: but that did not work either. Help will be very much appreciated.

<asp:QueryStringParameterDefaultValue="1"Name="totlabchg"QueryStringField="laborcharge"Type="Decimal"/>__________________<InsertParameters><asp:FormParameterDefaultValue="0"FormField="txtaccount"Name="ActNumber"Type="String"/><asp:FormParameterDefaultValue="0"FormField="txtmeter"Name="MeterNumber"Type="String"/><asp:FormParameterDefaultValue="0"FormField="txtdov"Name="VisitDate"Type="DateTime"/><asp:FormParameterDefaultValue=""FormField="txtsvadd"Name="SvAdd"Type="String"/><asp:ParameterName="TampId2"Type="Int32"/><asp:ParameterDefaultValue="64.44"Name="charge1"Type="Decimal"/><asp:FormParameterFormField="txtq1"Name="quantity1"Type="Int32"/><asp:QueryStringParameterDefaultValue="1"Name="subtotal1"QueryStringField="sub1"Type="Decimal"/><asp:FormParameterDefaultValue="1"FormField="txtpeople"Name="labor"Type="Int32"/><asp:FormParameterDefaultValue="1"FormField="txthrs"Name="laborhrs"Type="Decimal"/><asp:FormParameterDefaultValue="1"FormField="txttotlab"Name="totlabchg"Type="Decimal"/><asp:ParameterDefaultValue="300.00"Name="flatrate"Type="Decimal"/><asp:FormParameterDefaultValue="1"FormField="txttotalcharge"Name="totalcharge"Type="Decimal"/><asp:FormParameterDefaultValue="1"FormField="txtgrandtotal"Name="grandtotal"Type="Decimal"/><asp:ParameterDirection="ReturnValue"Name="RETURN_VALUE"Type="Int32"/></InsertParameters>

Thanks.

First, I have no idea what you're doing, so I'm working a little blind. Can you put a breakpoint in your app to see whether or not the calculated field is populated before the insert? You might have to put code into an event to see what's going on. Second, if you're using a stored procedure to do the insert, and it has the values that you're doing the calculation on, why not have it generate the calculated field? That might be easier in the short term.