.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> VB.Net >> Post New QuestionBookmark and Share Subscribe to Forum

query doubt

Posted By: bas     Posted Date: March 30, 2012    Points:5   Category :VB.Net
In select query i have to perform two action that is i want to view all the datas in gridview from database and i also want sum(amount) as total in the same gridview.what is the query for that.please help.i am using this query=
"select * from bill and select sum(amount) AS Total from bill".but showing syntax error.what is the correct syntax.please provide me correct query for this.
Thanks in advance.

here is m coding
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim con As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\billing.mdb"
Dim con1 As New OleDbConnection(con)
Dim qry As String = "SELECT * FROM bill and sum(amount) AS Total from bill"
Dim da As New OleDbDataAdapter(qry, con)
Dim ds As New DataSet()
da.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
End Sub

i have syntax error in query.

Responses
Author: Narayanan             
Posted Date: March 30, 2012     Points: 20   

Hi,
Your query is wrong...
Select * from bill -- It gets all the columns data from bill.
Select * from bill and sum(Amount) as Total from bill -- No meaning in this statement.

Please try this way..
for ex:
select Invoiceno,sum(amount) as [Total] from bill group by Invoiceno.


Regards, Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
Author: bas             
Posted Date: March 30, 2012     Points: 20   

what is that invoiceno?

Author: Narayanan             
Posted Date: March 30, 2012     Points: 20   

Hi,
it is a Column name of bill Table.I gave a Example query .

Regards, Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend