Click here to Skip to main content
15,916,215 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear all,

I am trying to export the date from datatable to excel. But i am not getting the records.

This is where i am passing the values:
VB
Dim cons As String = My.Settings.DBRestroConnectionString

Dim rdate As String = Format(DateTimePicker1.Value, "dd-MM-yyyy")

st = "SELECT BillMaster_1.Date, BillMaster_1.BillNo, BillMaster_1.TableNo, BillMaster_1.WaiterNo,  BillMaster_1.CoverNo, BillMaster_1.BillAmount, PayModeMaster.PayMode, (SELECT SUM(BillAmount) AS TotalAmount FROM BillMaster) AS 'Total' FROM BillMaster AS BillMaster_1 LEFT OUTER JOIN PayModeMaster ON BillMaster_1.PaidMode = PayModeMaster.PayModeId"

FN = "BillSummary"

moh = valq.excelexport(cons, st, FN, "BillMaster_1.Date", rdate)


function:
VB
Dim Xlapp As New Microsoft.Office.Interop.Excel.Application
       Dim TOTALcount As Integer
       ' Dim DT As Date
       Dim sqlcon As New SqlConnection(constr)
       Dim sqlcommd As New SqlCommand
       sqlcommd.Connection = sqlcon
       sqlcommd.CommandText = sqlstr + " where " + filter >= +"@x"
       sqlcommd.Parameters.AddWithValue("@x", para)
       'sqlcommd.Parameters.AddWithValue("Date", DT)
       Dim sqlda As New SqlDataAdapter(sqlcommd)
       Dim sqldt As New DataTable
       sqlda.Fill(sqldt)
       TOTALcount = sqldt.Rows.Count
       If sqldt.Rows.Count > 0 Then

I am getting zero records everytime.

Regards,
Mohinder Singh
Posted
Updated 5-Jul-12 19:25pm
v3
Comments
Sebastian T Xavier 6-Jul-12 2:52am    
please review your query and use improve question to correct it
Sergey Alexandrovich Kryukov 6-Jul-12 3:07am    
How do you know that this command should query some results? Maybe the number of matching records is really zero?
--SA
Simon_Whale 6-Jul-12 5:51am    
have you run the query in the database? does it return values there?
mvengaqua 6-Jul-12 7:28am    
Yes i have run the query in the database and it is showing records

1 solution

Remove the join and see what happens.

p.s. Your query has some unwanted characters. Use Preview button before hit Post.

Regards
Sebastian
 
Share this answer
 
Comments
mvengaqua 6-Jul-12 3:19am    
Dear Sebastian,

This is where i am passing the values:

Dim cons As String = My.Settings.DBRestroConnectionString

Dim rdate As String = Format(DateTimePicker1.Value, "dd-MM-yyyy")

st = "SELECT BillMaster_1.Date, BillMaster_1.BillNo, BillMaster_1.TableNo, BillMaster_1.WaiterNo, BillMaster_1.CoverNo, BillMaster_1.BillAmount, PayModeMaster.PayMode, (SELECT SUM(BillAmount) AS TotalAmount FROM BillMaster) AS Total FROM BillMaster AS BillMaster_1 LEFT OUTER JOIN PayModeMaster ON BillMaster_1.PaidMode = PayModeMaster.PayModeId

FN = "BillSummary"

moh = valq.excelexport(cons, st, FN, "BillMaster_1.Date", rdate)

Function:

Dim Xlapp As New Microsoft.Office.Interop.Excel.Application
Dim TOTALcount As Integer
Dim DT As Date
Dim sqlcon As New SqlConnection(constr)
Dim sqlcommd As New SqlCommand
sqlcommd.Connection = sqlcon
sqlcommd.CommandText = sqlstr + " where " + filter + ">= @x"
sqlcommd.Parameters.AddWithValue("@x", para)
Dim sqlda As New SqlDataAdapter(sqlcommd)
Dim sqldt As New DataTable
sqlda.Fill(sqldt)
TOTALcount = sqldt.Rows.Count
If sqldt.Rows.Count > 0 Then

It was nothing but the marks inserted my the window itself.
Now have a look. I run this query in sql it returns rows. But not here.

Regards,
MOhi

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