Dears,
For my C# windows application I want to select data from a datatable based on certain condition.In other words I want to use query "select * from datatable where transationName = 'Sales' and transDate = #1/1/2011#" on a datable in visual studio 2005.
Thanks In Advance,
With Warm Regards,
Ashrafuddin.T
Loading

Mayur GujrathiRank #666 · 3.6K reputationPosted May 28, 2011, 12:07 AM EDT
raghu v52 reputationPosted Jun 1, 2011, 6:18 AM EDT
u can do in the following fassion also
later on u can loop the drarray to get the work done
like
foreach(DataRow dr in drarray)
{
//do some thing with dr
}
Regards,
Raghavendra.V
Vilas GiteRank #951 · 2.1K reputationPosted Jun 1, 2011, 7:07 AM EDT
you may bind data with using store procedure with such a criteria.
1st create Store procedure---
--bind data with Query.
http://www.c-sharpcorner.com/UploadFile/73ba73/7161/?ArticleID=63b40f15-b9a8-4e27-a4f1-0625b4be4c55
Suthish NairRank #92 · 22.8K reputationPosted Jun 1, 2011, 11:01 AM EDT
ashrafuddin22 reputationPosted Jun 1, 2011, 9:55 PM EDT
Thanks EveryOne, for your prompt reply.
Dear Suthish Nair,
I am little familiar with LINQ,I think this feature is not present in vs2005.
Any how once again thanks for reply
With Regards,
Ashrafuddin.T
Suthish NairRank #92 · 22.8K reputationPosted Jun 1, 2011, 10:24 PM EDT
You can use .Select() of DataTable or RowFilter of DataView.
Do a search for samples..
Link
Link
ashrafuddin22 reputationPosted Jun 1, 2011, 11:04 PM EDT
Thanks for your reply.
Can you explain me how can I use this query in which there are 2 column in the where condition "select * from datatable where transationName = 'Sales' and transDate = #1/1/2011#"
With Regards,
Ashrafuddin.T
Vilas GiteRank #951 · 2.1K reputationPosted Jun 2, 2011, 12:05 AM EDT
You may use nested/Subqueries for your post.
check syntax with example:
http://www.marc-grange.net/SQL5_en.htm
---------------------------------------------------------------------
If this reply solve your post…then "MARK AS ANSWER"!raghu v52 reputationPosted Jun 2, 2011, 3:26 AM EDT
can u explain me ur requirement bitter clearly i predict ur requirement is as follow
first u will get the data from data table using stored procedure/command as below
sqlCommand mycomm=new SqlCommand("select * from datatable",conn_obj)
mycomm.CommandType=CommandType.Text;
SqlDataAdopter da=new SqlDataAdapter();
da.SelectCommand=mycomm;
DataSet ds=new DataSet();
da.Fill(ds,"Sales");
then if u want to filter then u can do as below
DataTable Dt= new DataTable();
String filterexp="transactionName="+"'sales'"+" and transdate='"+DateTime.Now.ToShortDate();
DataRow[] drarray;
drarray=dt.select(filterexp);
foreach(DataRow dr in drarray)
{
//do somthing with dr
}
else u can write the store procedure for with the parameters and can call the stored procedure every time
ashrafuddin22 reputationPosted Jun 2, 2011, 10:56 PM EDT
Thanks for your reply.
Consider the requirement as under.
Env: vs2005 and ms access (I hate both of these but cant change to other).
After a long and 2 many joins i am able to get a table which consist of following like records
TranDate quantity TransName
1-2-2011 10 Sales
1-2-2011 15 Purchase
2-2-2011 5 Sales
3-2-2011 10 Purchase
Now for a specific purpose i want the sales record separate and purchase record separate.But cant have any other query and also executing the same one more time query require additional resources.To any how reduce the time taken etc. to some extend I had decided to execute the query on the above data table like "select * from datatable where transname ='sales' and transDate= 1-2-2011
With Regards,
Ashrafuddin.T
raghu v52 reputationPosted Jun 3, 2011, 3:28 AM EDT
thnx for the data and if u have so many joins to get the data then it is not a good practice to hit the database again with the query so then it would be best if u proceed in the fashion i explained u in the earlier reply and after applying the filter the drarry will contain the rows which suites u r need and u can access the each field in follwing way
foreach(datarow dr in drarry)
{
date transdate=Convert.ToDate(dr["TranDate"].ToString());
int Quantity=Convert.ToInt32(dr["quantity"].ToString());
string Name=dr["TransName"].ToString();
}
make sure the fields in dr are case sensitive and same as the in Dataset/datatable
Happy coding
ashrafuddin22 reputationPosted Jun 6, 2011, 12:01 AM EDT
Thanks For your reply.hope your suggestion might work fine.Mean while i have executed the query twice to the beat the deadline.And will be implementing it later on, while bug fixing.
With Regards,
AShrafuddin.T