473,378 Members | 1,106 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,378 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 1157

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...
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...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.