Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

Please check the below code

SQL
If (DateTime.Now = "01/01/2013") Then
               Dim sql00 = "select sum(EL),sum(ML) from attendance where Emp_name = '" + ComboBox1.Text + "'"
               Dim sql000 = sql00 + " SELECT 15+ sum(EL) as el, 14 + sum(ML) as ml from attendance where Emp_name = '" + ComboBox1.Text + "' "
               DataGridView2.Rows.Add(sql000)
           End If

Please tell me whether the code is correct or not and i want to display the value of sql000 to a existing gridview...

please tell me how to do it..
Posted
Comments
vivektiwari97701 30-Oct-12 2:30am    
u have written 2 select Query and mearge that in to sql1000 its totaly wrong ...pls explain wat is ur requrment ??/
[no name] 30-Oct-12 2:33am    
my requirement is if the date hits 1/1/2013 then it should add the result of the first query(i.e. it will give the remaining leaves of a particular emp) to the nxt query(i.e. predefined number of leaves for each emp) and the result i want to display in the gridview
satz_770 30-Oct-12 2:38am    
hi, u need to display result of both queries in the same gridview or different??... u cant execute two queries that is in same variable.. u can execute it separately... u have not executed query... Execute it to get result and then bind it to grid....
[no name] 30-Oct-12 2:40am    
I want to display in same gridview..but not getting how to add the quries..please tell me some examples
satz_770 30-Oct-12 3:19am    
No use in adding two queries..
1. Execute the first query and Get the result..
2. Execute the second query and get the result..
3. add both the results based on ur requirement..
if u have any clarifications reply to this..

just update your query


SQL
select sum(EL),sum(ML),15+ sum(EL) as el, 14 + sum(ML) as ml from attendance where Emp_name = '" + ComboBox1.Text + "'"
 
Share this answer
 
v2
Comments
[no name] 30-Oct-12 3:04am    
Thanks @vivektiwari97701
hi,

Here is the code to connect to the database in Ms Access.

Connection string for MS Access via OLE DB:
Dim connection As OleDbConnection
connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\NorthWind.mdb;User Id=;Password=;")
connection.Open();

After connecting to the database

dim da as new oledb.oledbdataadapter("your query",connection)
dim ds as new dataset
da.fill(ds)

Now u can set the data to the grid....

DataGridView1.DataSource = ds
DataGridView1.DataMember = "table name"

Hope this helps

Refer these:

http://www.homeandlearn.co.uk/net/nets12p6.html
http://www.daniweb.com/software-development/vbnet/threads/44695/retrieve-data-by-vb.net[^]
http://stackoverflow.com/questions/6353889/how-to-retrieve-data-from-database-using-select-query[^]

mark it if u find it usseful....
 
Share this answer
 
v3

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