473,326 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to display database info into excel cells

Hi there,
I'm using microsoft visual studio 2005, with c# code. I recently downloaded GemBox which is a spreadsheet for excel. I can pass parameters through textboxes, comboboxes, labels...etc and display it on cells in excell. But now Im calling parameters directly from the database...I would like to know how to display it in excel...Here is part of the code I'm working on: (How can I make it work?)

ExcelFile ef = new ExcelFile();
ef.LoadXls("C:/Invoice.xls");
ExcelWorksheet ws = ef.Worksheets[0];

string sqlq = " SELECT Guest.GuestID, Guest.GuestFirstName, Guest.GuestLastName, Guest.GuestAddress, Guest.GuestEmail, Guest.Country, Guest.GuestPhone, Sales.GuestID, Sales.Date, Sales.Quantity, Sales.SaleItem, Sales.SalePrice, Sales.SaleTotal, Sales.SaleDiscount, FROM Guest Sales LEFT JOIN GuestID Sales ON Guest.GuestID = Sales.GuestID WHERE Guest.GuestID && Sales.GuestID = @GuestID ";
myCommand.CommandText = sqlq;
myCommand.Parameters.Add("@GuestID ", SqlDbType.Int).Value = 12345;
myCommand.Parameters.Add("@GuestFirstName ", SqlDbType.VarChar).Value = ws.Cells["D13"].Value;
myCommand.Parameters.Add("@GuestLastName ", SqlDbType.VarChar).Value = ws.Cells["D13"].Value;
myCommand.Parameters.Add("@GuestAddress ", SqlDbType.VarChar).Value = ws.Cells["D14"].Value;
myCommand.Parameters.Add("@GuestEmail ", SqlDbType.VarChar).Value = ws.Cells["D15"].Value;
myCommand.Parameters.Add("@Country ", SqlDbType.VarChar).Value = ws.Cells["H15"].Value;
myCommand.Parameters.Add("@GuestPhone ", SqlDbType.DateTime).Value = ws.Cells["D16"].Value;
myCommand.Parameters.Add("@Date ", SqlDbType.DateTime).Value = ws.Cells["M13"].Value;
myCommand.Parameters.Add("@Quantity ", SqlDbType.Int).Value = ws.Cells["C19"].Value;
myCommand.Parameters.Add("@SaleItem ", SqlDbType.VarChar).Value = ws.Cells["D19"].Value;
myCommand.Parameters.Add("@SalePrice ", SqlDbType.Money).Value = ws.Cells["L19"].Value;
myCommand.Parameters.Add("@SaleTotal ", SqlDbType.Money).Value = ws.Cells["M19"].Value;
myCommand.Parameters.Add("@SaleDiscount ", SqlDbType.VarChar).Value = ws.Cells["L38"].Value;
Dec 3 '07 #1
0 1153

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
3
by: EMW | last post by:
How can I put everything that is in a datagrid into a SQL server database (which should be readable by an PocketPC program)? There is probably a simple solution for it, but as always it is...
4
by: ctkevin | last post by:
I am an experienced Access user but recently moved an Access database to the web for my employer. We use a host that does not allow the use of data access pages. Is there anyway to pre-build a...
4
by: Powerguy | last post by:
Hi all, I've spent countless hours trying to get this silly EXCEL process to close once I have used it. If anyone can help it would really REALLy be appreciated! Below is my code- Dim t As...
1
by: RickH | last post by:
..Cells(1,y).GetType ownly shows instead of .Value, .Copy, etc. The code below is derived from samples, it should work, but I've messed up somewhere... Imports System.Windows.Forms Imports...
2
by: Agnes | last post by:
I can export the data to an excel(quit slow , for 5k records, It need 20mins) Now, my problem is how can I join another table from another database ? "select I.invno,I.company,C.telno,C.faxno from...
16
by: alexia.bee | last post by:
Hi all, In some weird reason, excel instance won;t die if i remove the comment from 4 lines of setting values into struct. here is a snipcode public...
1
by: DennisBetten | last post by:
First of all, I need to give some credit to Mahesh Chand for providing me with an excellent basis to export data to excel. What does this code do: As the title says, this code is capable of...
1
by: randyse | last post by:
Hello all, This is my first post, please let me know if I've missed any relevant data or guidelines. I'm using Access 2003 for the database and Excel 2003 for the reporting to avoid having...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.