471,082 Members | 765 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,082 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 1018

Post your reply

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

Similar topics

13 posts views Thread by Allison Bailey | last post: by
3 posts views Thread by EMW | last post: by
4 posts views Thread by ctkevin | last post: by
4 posts views Thread by Powerguy | last post: by

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.