Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Import data from excel cell to Textbox

Import data from excel cell to Textbox

Scheduled Pinned Locked Moved ASP.NET
csharptutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samsonx
    wrote on last edited by
    #1

    Hi, I have an excel containing mail address For example: In excel "column B" i have a number of email address in B1,B2,B3.... Now the thing i want each email address from B1,B2,B3 into my TextBox1.Text. Am using vb.net with c# language. Can anyone send me the code or give me some idea?. Thanks in advance.

    With Regards, Samson

    G 1 Reply Last reply
    0
    • S samsonx

      Hi, I have an excel containing mail address For example: In excel "column B" i have a number of email address in B1,B2,B3.... Now the thing i want each email address from B1,B2,B3 into my TextBox1.Text. Am using vb.net with c# language. Can anyone send me the code or give me some idea?. Thanks in advance.

      With Regards, Samson

      G Offline
      G Offline
      Greg Chelstowski
      wrote on last edited by
      #2

      If your spreadsheet is structured as a table in a database would be, you can use OleDb to connect to it, select the Column you want (select [column b] from $Sheet1), and then iterate through the collection to put stuff in the TextBox.

      private void ConnectToExcel(string Location)
      {
      string ConnectionStr = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended properties=\"Excel 8.0;HDR=YES\"", Location);
      try
      {
      OleDbConnection Connection = new OleDbConnection(ConnectionStr);

                  Connection.Open();
                             
                  string SelectString = "select \[column b\] from $Sheet1";
                  OleDbCommand Command = new OleDbCommand(SelectString, Connection);
                   OleDbDataReader olDbRead = Command.ExecuteNonQuery();
      
                  while (olDbRead.Read)
                  {
                      textBox1.Text += olDbRead\[0\].ToString();
                  }
      
                  
                  
              }
              catch{}
              finally{Connection.Close();}
      

      }

      samsonx wrote:

      Am using vb.net with c# language.

      Well you lost me here...

      var question = (_2b || !(_2b));

      K 1 Reply Last reply
      0
      • G Greg Chelstowski

        If your spreadsheet is structured as a table in a database would be, you can use OleDb to connect to it, select the Column you want (select [column b] from $Sheet1), and then iterate through the collection to put stuff in the TextBox.

        private void ConnectToExcel(string Location)
        {
        string ConnectionStr = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended properties=\"Excel 8.0;HDR=YES\"", Location);
        try
        {
        OleDbConnection Connection = new OleDbConnection(ConnectionStr);

                    Connection.Open();
                               
                    string SelectString = "select \[column b\] from $Sheet1";
                    OleDbCommand Command = new OleDbCommand(SelectString, Connection);
                     OleDbDataReader olDbRead = Command.ExecuteNonQuery();
        
                    while (olDbRead.Read)
                    {
                        textBox1.Text += olDbRead\[0\].ToString();
                    }
        
                    
                    
                }
                catch{}
                finally{Connection.Close();}
        

        }

        samsonx wrote:

        Am using vb.net with c# language.

        Well you lost me here...

        var question = (_2b || !(_2b));

        K Offline
        K Offline
        krishna_goluguri
        wrote on last edited by
        #3

        hi weather this code works perfectly or not i don't know bcoz when i wanted to use oledb connection for excel sheet my program didnt accept that one.it says it as unrecognized format.how to connect excel sheet using oledb connection plz explain step by step.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups