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
Solved

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

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

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

840 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