Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Data Saving(2) 2 41
Image(7) 1 53
DateTimepicker 4 33
C# HTTP GET method sample code 3 39
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

919 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

15 Experts available now in Live!

Get 1:1 Help Now