Solved

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

Posted on 2007-03-29
2
603 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
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now