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
ashrafuddinPosted Jun 6, 2011, 4:01 AM
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
raghu vPosted Jun 3, 2011, 7:28 AM
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
ashrafuddinPosted Jun 3, 2011, 2:56 AM
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 vPosted Jun 2, 2011, 7:26 AM
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
Vilas GitePosted Jun 2, 2011, 4:05 AM
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"!ashrafuddinPosted Jun 2, 2011, 3:04 AM
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
Suthish NairPosted Jun 2, 2011, 2:24 AM
You can use .Select() of DataTable or RowFilter of DataView.
Do a search for samples..
Link
Link
ashrafuddinPosted Jun 2, 2011, 1:55 AM
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 NairPosted Jun 1, 2011, 3:01 PM
Vilas GitePosted Jun 1, 2011, 11:07 AM
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
raghu vPosted Jun 1, 2011, 10:18 AM
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
Mayur GujrathiPosted May 28, 2011, 4:07 AM
Dim dataParentTable As DataTable = New DataTable("Parent") ' e.g. dataParentTable.selectcommand("SELECT * WHERE [column] = [XYZ]")