问题打包问~
有两个问题请问:
1.select distinct Dcode as 代码,Dname as 名称,Convert(varchar(10),Datetime,120) as 购买日期,Ocost as 净值,Dup as [增长率(%)],mumber as 份额,Ocost*mumber as 市值,Inmoney as [投入金额],Backmy as [赎回金额],Convert (numeric(12, 4), Dmony*mumber) as [当日盈亏], Convert (numeric(12, 4), Dmony*mumber/Inmoney) as [收益率(%)] from fundcost,mfund where Dcode = Codef and People = '" + id + "'
在这句sql语句上我想加多一个对select结果的一个排列"order by mumber",请问该怎么加?
2.我有一个dropdownlist
现在我为它添加数据源用dataset填充:
string conn = WebConfigurationManager.ConnectionStrings["EndDesignConnectionString"].ConnectionStr ing;
SqlConnection cn = new SqlConnection(conn);
cn.Open();
string strsql = "select Codef from mfund where People = '" + Session["uid"] + "'";
SqlDataAdapter myda = new SqlDataAdapter();
myda.SelectCommand = new SqlCommand(strsql, cn);
SqlCommandBuilder cmdbuilder = new SqlCommandBuilder(myda);
DataSet ds = new DataSet();
myda.Fill(ds, "mfund");
DropDownList1.DataSource = ds;
DropDownList1.DataBind();
//DropDownList1.DataTextField = "Codef";
myda.Update(ds, "mfund");
cn.dispose();
cn.close();
然后我将dropdownlist的datatextfield和datavaluefield都设置为Codef。
显示是没问题,然后我再用SelectedIndexChanged事件编写代码:
string conn = WebConfigurationManager.ConnectionStrings["EndDesignConnectionString"].ConnectionString;
SqlConnection cn = new SqlConnection(conn);
cn.Open();
string code = DropDownList1.SelectedValue.ToString();
// int cc = Convert.ToInt32(code);
SqlCommand cmd = new SqlCommand("select Ocost from fundcost where Dcode ='" + code + "'", cn);
double cost = Convert.ToDouble(cmd.ExecuteScalar());
cmd.Dispose();
cmd.CommandText = "select Dname from fundcost where Dcode='" + code + "'";
string name = Convert.ToString(cmd.ExecuteScalar());
cmd.Dispose();
Label4.Text = name + "的单位净值是:" + cost;
cn.Dispose();
cn.Close();
问题出来了,我运行的时候不管怎么选择dropdownlist里面的item,但是显示的总是第一个item的净值。
例如dropdownlist里面有21300,21311,不管我怎么选都选不了21311的净值。
|