Skip to content
Loading
  • 0
    Thanks Satyapriya Nayak
    but how to use windows form?
    I have project and show the data like this ,I hope, to Import Data from Excel to a SQL Server 2000 use c#??


    0
  • 0
    private void button1_Click(object sender, EventArgs e)
            {
                try
                {
                    System.Data.OleDb.OleDbConnection MyConnection;
                    System.Data.DataSet DtSet;
                    System.Data.OleDb.OleDbDataAdapter MyCommand;
                    MyConnection = new System.Data.OleDb.OleDbConnection(@"provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + button2.Text + "';Extended Properties=Excel 8.0;");
                    MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$] ", MyConnection);
                    MyCommand.TableMappings.Add("Table", "TestTable");
                    DtSet = new System.Data.DataSet();
                    MyCommand.Fill(DtSet);
                    dataGridView1.DataSource =DtSet.Tables[0];
                    MyConnection.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }

            private void button2_Click(object sender, EventArgs e)
            {/*
                OpenFileDialog dlg = new OpenFileDialog();
                // Show all files
                dlg.Filter = string.Empty;
                dlg.ShowDialog();
                */

                /* all file dak terfokus
               
                 OpenFileDialog dlg = new OpenFileDialog();

                 // Filter by Word Documents OR Excel Worksheets OR PowerPoint Presentations
                 //           OR Office Files
                 //           OR All Files
                 *dlg.Filter = "Word Documents|*.doc|Excel Worksheets|*.xls|PowerPoint Presentations|*.ppt" +
                              "|Office Files|*.doc;*.xls;*.ppt" +
                              "|All Files|*.*";

                 dlg.ShowDialog();
                 */
                OpenFileDialog dlg = new OpenFileDialog();

                // Filter by Excel Worksheets
                dlg.Filter = "Excel Worksheets|*.xls";

                dlg.ShowDialog();
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    button2.Text = Convert.ToString(dlg.FileName);
                    //pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                    //pictureBox1.Image = Image.FromFile(openFile.FileName);
                }
          
            }
    0