Click here to Skip to main content
15,886,639 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
protected void DropDownList1_TextChanged(object sender, EventArgs e)
{
    SqlDataAdapter dam = new SqlDataAdapter("select * from Net_calculate where DistrictName='" + DropDownList1.Text + "'", con);
    DataSet dsm = new DataSet();
    // add this line to define table name in dataset 
    //dam.Tables.Add("Net_calculate");
    dsm.Tables.Add("Net_calculate");
    dam.Fill(dsm, "Net_calculate");
    DataView dvm = new DataView(dsm.Tables["Net_calculate"]);
    txtAmt.Text = dvm[0]["net_amount"].ToString();
}
Posted
Updated 21-Feb-13 21:54pm
v2
Comments
Sergey Alexandrovich Kryukov 12-Mar-13 15:41pm    
What you really need is using the debugger. Did you ever try? I remember I advised that, but you did not respond...
—SA

1 solution

Try this:
C#
protected void DropDownList1_TextChanged(object sender, EventArgs e)
{
    SqlCommand cmd = new SqlCommand("select * from Net_calculate(@dst)", con);
    cmd.CommandType = CommandType.Text
    cmd.Parameters.Add(New Data.SqlClient.SqlParameter("@dst", input));
    cmd.CommandTimeout = 0;
    SqlDataAdapter dam = new SqlDataAdapter(cmd);
    DataTable dtm = new DataTable("Test");
    // add this line to define table name in dataset 
    //dam.Tables.Add("Net_calculate");
    dam.Fill(dtm );
    if(dtm != null){
        if(dtm .Rows.Count > 0){
            txtAmt.Text = dtm .Rows[0]["net_amount"].ToString();
        }
    }
}



--Amit
 
Share this answer
 
v3
Comments
Gilbertinino 22-Feb-13 4:07am    
This code is not displaying data retrieved to the txtAmt.Text.
_Amy 22-Feb-13 4:11am    
Yes, because the table is not having any data.
See my updated answer. Try to put a breakpoint and step through the code.

--Amit
Gilbertinino 22-Feb-13 4:33am    
Am not using data from table but data retrieved are from a function called Net_calculate not a table and those data are predefined in the function.
_Amy 22-Feb-13 4:40am    
In your question, it's very very clear that you are assigning the name of your datatable as Net_calculate.
Anyway, where is your Net_calculate function? Can I see the code?

But I think solution is clear. You are taking the data from database based on dropdown list selected text. The data coming from database is stored in a datatable named Net_calculate. Using that datatable you are assigning the text to your textbox.

--Amit
Gilbertinino 22-Feb-13 4:51am    
The below is the function am using
and while exec it,it gives me data according to the district

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

alter FUNCTION [dbo].[Net_calculate]
(
@dst nvarchar(50)
--@pst nvarchar(50)
)
RETURNS @tableout TABLE(net_amount int)
AS
BEGIN
declare @dist nvarchar(50),@amt1 int,@post nvarchar(50),@amt2 int
select @dist=DistrictName from District where DistrictName=@dst
--SELECT @post=poste FROM employee WHERE poste = @pst

----------------------------PS-----------------------------
--if(@post='PS')
--begin
if(@dist='KIGALI')or(@dist='RUBAVU') or (@dist='MUSANZE')
begin
set @amt1=58750+8000
insert into @tableout values(@amt1)
select @amt1=net_amount from mission
end
--end
--if(@post='PS')
--begin
if(@dist='HUYE')or (@dist='RUSIZI') or (@dist='KARONGI')
begin
set @amt1=40250+8000
insert into @tableout values(@amt1)
end
--end
--if(@post='PS')
--begin
if(@dist='others')
begin
set @amt1=27000+8000
insert into @tableout values(@amt1)
end

RETURN
END

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900