patterncsharpModerate
Loading either all shops or a specifically named shop from a DataTable
Viewed 0 times
shopsalldatatablespecificallynamedeitherloadingshopfrom
Problem
public delegate DataTable loadDataTable();
DataTable shops = (cmbShop.Text == "All Shops") ?
new loadDataTable(() =>
{
Program.con.GET_Table_From_DataBase("sh", "select * from shops ");
return Program.con.dst.Tables["sh"];
}
).Invoke()
:
new loadDataTable(() =>
{
Program.con.GET_Table_From_DataBase("sh", "select * from shops where shopname='" + cmbShop.Text + "' ");
return Program.con.dst.Tables["sh"];
}
).Invoke();I am just setting the value of
DataTable shops here.I am learning about lambda expressions, so just for learning purposes, I want to know if this code can be shortened while using lambda expressions.
Solution
You don't need any lambda expressions at all.
You can write
You can write
if (cmbShop.Text == "All Shops")
Program.con.GET_Table_From_DataBase("sh", "select * from shops ");
else
Program.con.GET_Table_From_DataBase("sh", "select * from shops where shopname='" + cmbShop.Text + "' ");
DataTable shops = Program.con.dst.Tables["sh"];Code Snippets
if (cmbShop.Text == "All Shops")
Program.con.GET_Table_From_DataBase("sh", "select * from shops ");
else
Program.con.GET_Table_From_DataBase("sh", "select * from shops where shopname='" + cmbShop.Text + "' ");
DataTable shops = Program.con.dst.Tables["sh"];Context
StackExchange Code Review Q#2937, answer score: 11
Revisions (0)
No revisions yet.