Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL-Server
Hi all
 
Please check the below code
 
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 29-Oct-12 21:11pm
Comments
vivektiwari97701 at 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 ??/
snehasish nandy at 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 at 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....
snehasish nandy at 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 at 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..
snehasish nandy at 30-Oct-12 3:20am
   
Give me some example...
shanalalkasim at 30-Oct-12 3:02am
   
U have not executed query,
1. Execute query
2. fetch the result
3. Bind it to grid
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

just update your query
 

select sum(EL),sum(ML),15+ sum(EL) as el, 14 + sum(ML) as ml from attendance where Emp_name = '" + ComboBox1.Text + "'"
  Permalink  
v2
Comments
snehasish nandy at 30-Oct-12 3:04am
   
Thanks @vivektiwari97701
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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....
  Permalink  
v3

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

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 30 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100