Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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"
Posted
Updated 30-May-16 18:00pm
v3
Comments
Karthik_Mahalingam 26-May-16 12:38pm    
DataTable or DataGridView ?
George Jonsson 26-May-16 18:34pm    
Is it a Windows Form project?
Are you showing the data in the data table in a DataGridView?

1 solution

Try this.
C#
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]
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900