选择表格中列的最后一行并显示在文本框中 [英] Select last row of column in table and show in textbox

查看:128
本文介绍了选择表格中列的最后一行并显示在文本框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆