如何从数据表中提取所选行的选定值并将其显示在文本框中... [英] How do I fetching the selected row selected value from datatable and display it in textbox...

查看:63
本文介绍了如何从数据表中提取所选行的选定值并将其显示在文本框中...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有从数据库中获取的值...(字段是Transction类型,事务类别,日期,金额,供应商)



来自数据表,如果我选择或点击任何行,行值应显示在文本框中...例如

它应显示为



"交易类型=生活方式金额= 1000供应商=净播放

解决方案

试试这个。

  private   void  GetRowsByFilter()
{
var DataSet1 = new DataSet();

var table1 = new DataTable( 订单);
DataSet1.Tables.Add(table1);
var table = DataSet1.Tables [ 订单];
table.Columns.Add( new DataColumn {Caption = Transction type,ColumnName = Transctiontype,DataType = typeof string )});
table.Columns.Add( new DataColumn {Caption = 事务类别,ColumnName = Transactioncategory,DataType = typeof string )});
table.Columns.Add( new DataColumn {Caption = Date,ColumnName = 日期,DataType = typeof (DateTime)});
table.Columns.Add( new DataColumn {Caption = Amount,ColumnName = 金额,DataType = typeof int )});
table.Columns.Add( new DataColumn {Caption = Vendor,ColumnName = 供应商,DataType = typeof string )});


var newRw = table.NewRow();
newRw [ Transctiontype] = 生活方式;
newRw [ Date] = DateTime.Now;
newRw [ 金额] = 1000 ;
newRw [ 供应商] = 网络游戏;
table.Rows.Add(newRw.ItemArray);

newRw = table.NewRow();
newRw [ Transctiontype] = 非生活方式;
newRw [ Date] = DateTime.Now;
newRw [ 金额] = 15000 ;
newRw [ 供应商] = Microsoft;
table.Rows.Add(newRw.ItemArray);

newRw = table.NewRow();
newRw [ Transctiontype] = 生活方式;
newRw [ Date] = DateTime.Now;
newRw [ 金额] = 15000 ;
newRw [ 供应商] = CodeProject;
table.Rows.Add(newRw.ItemArray);

string 表达式;

expression = 金额= 1000且Transctiontype ='生活方式'和供应商='净玩';
DataRow [] foundRows;

foundRows = table.Select(expression);

if (foundRows.Any())
{
/ / textbox.text = foundRows [0] .ItemArray [0]
}
}


I Am having datatable full of values fetched from database...(the fields are Transction type,Transaction category, Date,Amount , Vendor)

from that datatable if i select or click on any row that row value should be displayed in a textbox...for example
It should display as

"Transaction type= Life style amount=1000 vendor= Net play"

解决方案

Try this.

private void GetRowsByFilter()
        {
            var DataSet1 = new DataSet();

            var table1 = new DataTable("Orders");
            DataSet1.Tables.Add(table1);
            var table = DataSet1.Tables["Orders"];
            table.Columns.Add(new DataColumn { Caption = "Transction type", ColumnName = "Transctiontype", DataType = typeof(string) });
            table.Columns.Add(new DataColumn { Caption = "Transaction category", ColumnName = "Transactioncategory", DataType = typeof(string) });
            table.Columns.Add(new DataColumn { Caption = "Date", ColumnName = "Date", DataType = typeof(DateTime) });
            table.Columns.Add(new DataColumn { Caption = "Amount", ColumnName = "Amount", DataType = typeof(int) });
            table.Columns.Add(new DataColumn { Caption = "Vendor", ColumnName = "Vendor", DataType = typeof(string) });


            var newRw = table.NewRow();
            newRw["Transctiontype"] = "Life style";
            newRw["Date"] = DateTime.Now;
            newRw["Amount"] = 1000;
            newRw["Vendor"] = "Net play";
            table.Rows.Add(newRw.ItemArray);

            newRw = table.NewRow();
            newRw["Transctiontype"] = "Non Life style";
            newRw["Date"] = DateTime.Now;
            newRw["Amount"] = 15000;
            newRw["Vendor"] = "Microsoft";
            table.Rows.Add(newRw.ItemArray);

            newRw = table.NewRow();
            newRw["Transctiontype"] = "Life style";
            newRw["Date"] = DateTime.Now;
            newRw["Amount"] = 15000;
            newRw["Vendor"] = "CodeProject";
            table.Rows.Add(newRw.ItemArray);

            string expression;

            expression = "Amount = 1000 and Transctiontype = 'Life style' and vendor = 'Net play'";
            DataRow[] foundRows;

            foundRows = table.Select(expression);

            if (foundRows.Any())
            {
                //textbox.text = foundRows[0].ItemArray[0]
            }
        }


这篇关于如何从数据表中提取所选行的选定值并将其显示在文本框中...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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