Click here to Skip to main content
15,900,685 members
Home / Discussions / C#
   

C#

 
GeneralRe: Saving Data on a Form Pin
AspDotNetDev17-Feb-10 21:47
protectorAspDotNetDev17-Feb-10 21:47 
GeneralRe: Saving Data on a Form Pin
thomas_anderson20-Feb-10 11:29
thomas_anderson20-Feb-10 11:29 
QuestionReading from parallel port using c# Pin
A k ch17-Feb-10 17:41
A k ch17-Feb-10 17:41 
Questionplease forgive me for i know this is basic but i simply don't know how to add stuff a list like this Pin
tonyonlinux17-Feb-10 15:20
tonyonlinux17-Feb-10 15:20 
AnswerRe: please forgive me for i know this is basic but i simply don't know how to add stuff a list like this Pin
Dan Mos17-Feb-10 15:30
Dan Mos17-Feb-10 15:30 
GeneralRe: please forgive me for i know this is basic but i simply don't know how to add stuff a list like this Pin
tonyonlinux17-Feb-10 15:35
tonyonlinux17-Feb-10 15:35 
GeneralRe: please forgive me for i know this is basic but i simply don't know how to add stuff a list like this Pin
Dan Mos17-Feb-10 15:37
Dan Mos17-Feb-10 15:37 
GeneralRe: please forgive me for i know this is basic but i simply don't know how to add stuff a list like this Pin
tonyonlinux17-Feb-10 15:54
tonyonlinux17-Feb-10 15:54 
Hey one last thing if you have the time... What I'm trying to do using an example of course. is read my excel sheet columns a,b,c,d,e one row at a time into a list so I can take those values and hopefully insert them into a database. I have the database insert method working fine I just need to figure out how to get the data into a format so I can pass it to the stored procedure I made.

I'm aiming to get index[0].text index[1].text and so forth for each row... What I have so far gets the values of each row but one column at a time so lets say I have tony smith testing somethingelse 1.99
i get the following results
[0] tony
[1] smith
[2] testing
[3] somethingelse
[4] 1.99


what I'd like to do is label the results if all possible like first = [0], last =[0]
that way when i wanted to use the data i could simply do something like this
row.first
row.last
row.whatever

here is the code i have those for but I'm confused how to accomplish what i'm trying to do
private void importDataFromExcelToolStripMenuItem_Click(object sender, EventArgs e)
 {
     /*****************************************************************************
      * allows to read file from excel
      * reference: http://csharp.net-informations.com/excel/csharp-read-excel.htm
      * ******************************************************************************/
     OpenExcelFile.Title = "SELECT EXCEL FILE TO IMPORT FROM ";
     OpenExcelFile.Filter = "XLS FILES|*.XLS";
     OpenExcelFile.InitialDirectory = @"c:\";
     string filepath = null;
     if (OpenExcelFile.ShowDialog() == DialogResult.OK)
     {
         filepath = OpenExcelFile.FileName;
     }


     Excel.Application xlApp;
     Excel.Workbook xlWorkBook;
     Excel.Worksheet xlWorkSheet;
     Excel.Range range;

     xlApp = new Excel.ApplicationClass();
     xlWorkBook = xlApp.Workbooks.Open(filepath, 0, true, 5, "", "", true,
                                        Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t",
                                        false, false, 0, true, 1, 0);
     xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);


     List<string> strList= new List<string>();
     string str;
     int rCount = 0;//row counter
     int cCount = 0;//column counter

     range = xlWorkSheet.UsedRange;

     for (rCount = 1; rCount <= range.Rows.Count; rCount++)
     {
         for (cCount = 1; cCount <= range.Columns.Count; cCount++)
         {
             str = (string)(range.Cells[rCount, cCount] as Excel.Range).Value2;
             strList.Add(str);

         }
     }

     xlWorkBook.Close(true, null, null);
     xlApp.Quit();

     releaseObject(xlWorkSheet);
     releaseObject(xlWorkBook);
     releaseObject(xlApp);

 }

 private void releaseObject(object obj)
 {
     try
     {
         System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
         obj = null;
     }
     catch (Exception ex)
     {
         obj = null;
         MessageBox.Show("Unable to release the Object " + ex.ToString());
     }
     finally
     {
         GC.Collect();
     }
 }

GeneralRe: please forgive me for i know this is basic but i simply don't know how to add stuff a list like this [modified] Pin
Dan Mos17-Feb-10 16:21
Dan Mos17-Feb-10 16:21 
GeneralRe: please forgive me for i know this is basic but i simply don't know how to add stuff a list like this Pin
tonyonlinux17-Feb-10 19:33
tonyonlinux17-Feb-10 19:33 
GeneralRe: please forgive me for i know this is basic but i simply don't know how to add stuff a list like this Pin
Dan Mos17-Feb-10 20:03
Dan Mos17-Feb-10 20:03 
GeneralRe: please forgive me for i know this is basic but i simply don't know how to add stuff a list like this Pin
tonyonlinux18-Feb-10 2:01
tonyonlinux18-Feb-10 2:01 
GeneralRe: please forgive me for i know this is basic but i simply don't know how to add stuff a list like this Pin
Dan Mos18-Feb-10 2:50
Dan Mos18-Feb-10 2:50 
GeneralRe: please forgive me for i know this is basic but i simply don't know how to add stuff a list like this Pin
tonyonlinux18-Feb-10 9:19
tonyonlinux18-Feb-10 9:19 
NewsBookStore GPLv3 Project Pin
User 691845417-Feb-10 14:22
User 691845417-Feb-10 14:22 
GeneralRe: BookStore GPLv3 Project Pin
Not Active17-Feb-10 14:50
mentorNot Active17-Feb-10 14:50 
GeneralRe: BookStore GPLv3 Project Pin
Mycroft Holmes17-Feb-10 17:15
professionalMycroft Holmes17-Feb-10 17:15 
GeneralRe: BookStore GPLv3 Project Pin
User 691845417-Feb-10 17:35
User 691845417-Feb-10 17:35 
GeneralRe: BookStore GPLv3 Project Pin
Anubhava Dimri17-Feb-10 17:37
Anubhava Dimri17-Feb-10 17:37 
Questioncustom pipeline - biztalk 2009 - how to loop through Ibasemessage.bodypart Pin
challa_praveena17-Feb-10 13:02
challa_praveena17-Feb-10 13:02 
AnswerRe: custom pipeline - biztalk 2009 - how to loop through Ibasemessage.bodypart Pin
Mirko198017-Feb-10 22:48
Mirko198017-Feb-10 22:48 
QuestionMessage Removed Pin
17-Feb-10 11:38
JimBob SquarePants17-Feb-10 11:38 
AnswerRe: Trouble deleting items using generic xml provider. Pin
AspDotNetDev17-Feb-10 12:11
protectorAspDotNetDev17-Feb-10 12:11 
QuestionTreeView Pin
mbangh17-Feb-10 10:58
mbangh17-Feb-10 10:58 
AnswerRe: TreeView Pin
PIEBALDconsult17-Feb-10 12:09
mvePIEBALDconsult17-Feb-10 12:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.