Solved

Using stream reader to get Excel data. Almost works -- but data read comes out as gobblygook.

Posted on 2007-03-29
2
608 Views
Last Modified: 2008-01-09
Using my Visual C# Sharp 2005 Express Edition....

I am trying to read an Excel file so i can save it to a database. for now, I'm just trying to get the connection to work and see that I am reading the data properly. I don't really know what I'm doing, so I ask that if you answer with some specifics. Here is my code. The results I get are some gibberish in the textbox. Please don't suggest some other methods or using some other software or database or anything. i've been running around in circle with answers like that for about a week now. I just need something simple to get the excel data into my SQL server. This is really, really close since I DO know how to add/delete/modify my SQL data. If only I could just get some data to add! Any suggestions?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace WindowsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            System.IO.StreamReader FReader =
                new System.IO.StreamReader((System.Reflection.Assembly.GetExecutingAssembly().
                    GetManifestResourceStream("WindowsApplication2.Phrases.xls")));
            string str = (string) FReader.ReadToEnd().ToString();
            textBox1.Text = str;
            FReader.Close();
        }
    }
}
0
Comment
Question by:chevronrod
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
BaldProgrammer earned 250 total points
ID: 18820384
Chevronrod,

Is there a reason you've chosen not to use the Excel object that is available to use in .NET?  Microsoft has a KB on that:

http://support.microsoft.com/kb/306572/EN-US/

It is a web application, but the same concept can be applied to windows applications.  What the example does is uses a "DB connection" to open the excel file, once it is open, it can operate similar to a database connection.  Is this what you are looking for?

Best Regards,

BaldProgrammer
0
 

Author Comment

by:chevronrod
ID: 18821214
I had to do some manipulating but your answer got me 90% of the way there which was about 89% further than I was after spending days on this solutiion. Thank you very much.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question