如何在具有单个值的表中填充所有行 [英] How Do I Populate All Rows In A Table With A Single Value
本文介绍了如何在具有单个值的表中填充所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
string con_str = @"Data Source=DATABASE;Initial Catalog=abc;Integrated Security=True";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DropDownList1.Items.Clear();
DropDownList1.Items.Add("");
SqlConnection con = new SqlConnection(con_str );
con.Open();
string es = "select year from table1";
SqlCommand ees = new SqlCommand(es, con);
SqlDataReader rdr = ees.ExecuteReader();
while (rdr.Read())
{
DropDownList1.Items.Add(rdr.GetString(0));
}
DropDownList1.DataBind();
}
}
现在我想将此下拉列表值添加到新列中的另一个表格中
例如
dropdownselected - (2011)
sql roll name 年(已添加新栏目)
1 222 abx 2011
2 333 eeqa 2011
3 342 bdh 2011
i将选择2011这将填入所有行的表格
now i want to add this dropdown value to another table in a new column
for example
dropdownselected--(2011)
sql roll name year(new column added)
1 222 abx 2011
2 333 eeqa 2011
3 342 bdh 2011
i will select 2011 and this will populate in the table in all the rows
推荐答案
嗨
关于选定的索引更改事件参考MSDN文章:
MSDN-ListControl选定的索引更改事件 [ ^ ]
在那个事件中,只需通过下面的sql查询更新数据库表,方法是传递下拉列表的选定值
Hi
about selected index changed event refer MSDN article:
MSDN-ListControl Selected Index Changed Event[^]
In that event, just update the database table using below sql query by passing the selected value of the dropdown list
Declare @year int
set @year = @dropdownvalue --pass your dropdown value here
update table1 set year=@year
GO
希望这会有所帮助。
hope this helps.
UPDATE表设置新列='@ Dropar'来自'%'
这将更新记录表的所有行..
UPDATE table SET new column = '@year from Dropdown' where column like '%'
this will update all the rows of the recorded table..
这篇关于如何在具有单个值的表中填充所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文