选择表格中列的最后一行并显示在文本框中 [英] Select last row of column in table and show in textbox
问题描述
我的Windows窗体(form1)有文本框控件(textbox1),组合框控件(combobox1),它们都包含项目(table1 - table2 - table3)和sql数据库名称(database1),它有一个表格(table1 - table2 - table3)哪些是相同的,每个都包含列(itemcode - itemname - itemprice)
i想要根据表名显示列的最后一行(itemcode)我将从中选择combobox1
怎么做代码和控件的哪个事件请
请试试这样的事情
私人 void comboBox1_SelectedIndexChanged( object sender,EventArgs e)
{
Control [] ctrl = this .Controls.Find(comboBox1.SelectedItem.ToString(), true );
if (ctrl.Length > 0 )
{
DataGridView dgv =(DataGridView)ctrl [ 0 ];
textBox1.Text = dgv.Rows [dgv.Rows.Count - 1 ]。单元格[ 0 跨度>] Value.ToString();
}
}
从项目代码desc+ dropdownlist1.selecteditem.text +顺序中选择前1名
my windows form (form1) has textbox control (textbox1) , combobox control (combobox1) which all contain items (table1 - table2 - table3) and the sql database name (database1) and it has a tables (table1 - table2 - table3)which are identical each contains columns (itemcode - itemname - itemprice)
i want to show the last row of column(itemcode) according to table name i will choose from combobox1
how to do that in code and in which event of the controls please
Please try some thing like this
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { Control[] ctrl = this.Controls.Find(comboBox1.SelectedItem.ToString(),true); if (ctrl.Length > 0) { DataGridView dgv = (DataGridView)ctrl[0]; textBox1.Text = dgv.Rows[dgv.Rows.Count - 1].Cells[0].Value.ToString(); } }
select top 1 from "+dropdownlist1.selecteditem.text+" order by itemcode desc
这篇关于选择表格中列的最后一行并显示在文本框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!