?
Solved

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

Posted on 2007-03-29
2
Medium Priority
?
611 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 1000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

771 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