Winform中Excel导入到指定的表中,效果如图所示:
把制作的Excel表在Winform下导入到SQLServer中的“Test”表中,应该怎样实现???图中使用的Winform中的什么控件啊,“OpenFileDialog”、"SaveFileDialog"和"FolderBrowerDialog"控件好像都不行呢???

解决方案 »

  1.   

    openfiledialog 获取对象路径,
    然后自己实现导入代码。
      

  2.   

    一个文本框+一个普通的按钮,按钮的上显示“浏览”,点击按钮调用OpenFileDialog,打开文件选择对话框,确定后,获取选择的文件路径,使用OldDb来加载Excel数据到Datatable,之后用SqlBulkCopy快速导入到数据库中。
    你哪个步骤不会?
      

  3.   

    学习了,LZ不知道。可是小弟对“使用OldDb来加载Excel数据到Datatable”和“用SqlBulkCopy快速导入到数据库中”这两个步骤不会啊
      

  4.   

    一个文本框+一个普通的按钮,按钮的上显示“浏览”,点击按钮调用OpenFileDialog,打开文件选择对话框,确定后,获取选择的文件路径,使用OldDb来加载Excel数据到Datatable,之后用SqlBulkCopy快速导入到数据库中。
    你哪个步骤不会?
    思路正确,就是没有代码实例,遗憾
      

  5.   

    1、
      private void btnSelectFile_Click(object sender, EventArgs e)
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
                openFileDialog1.Filter = "Excel 文件(*.xls;*.xls)|*.xls;*.xls";
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    tbFileName.Text = openFileDialog1.FileName;
                }
            }2、
      private void btnRecive_Click(object sender, EventArgs e)
            {
                SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                saveFileDialog1.Filter = "Excel 文件(*.xls;*.xls)|*.xls;*.xls";//"Excel 文件(*.xlsx)|*.xlsx";
                DialogResult dialogResult1 = saveFileDialog1.ShowDialog();
                Application.DoEvents();            if (dialogResult1 == DialogResult.OK)
                {
                    string fileName = saveFileDialog1.FileName;
                    if (fileName != "")
                    {
                        CreateReport(fileName, DateType);
                    }
                }
            }
    3、// 读数据
                string fileName = tbFileName.Text;            DataTable dt = new DataTable();
                string strConn = "";
                strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1'";            using (OleDbConnection connection = new OleDbConnection(strConn))
                {
                    connection.Open();                // 取第一个SheetName                #region SheetName
                    DataTable schemaTable = connection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
                    string sheetName = schemaTable.Rows[0][2].ToString().Trim();
                    sheetName = FormatSheetName(sheetName);
                    #endregion
                    // 数据               
                    string strSqlSelect = "";
               
                    strSqlSelect = "SELECT  * FROM [" + sheetName + "] ";
                                           OleDbCommand command = new OleDbCommand(strSqlSelect, connection);
                    OleDbDataAdapter adapt = new OleDbDataAdapter(command);
                    DataSet ds = new DataSet();
                    adapt.Fill(ds);
               }