locked
Import from excel file RRS feed

  • Question

  • Hello, is it possible to read from an excel file and then import the data row by row.

    I know ado.net what I dont know is to open the excel file, and begin iterating in rows and columns of the excel file.

    Thanks very much for your help.
    Wednesday, September 28, 2005 9:55 PM

Answers

  • Hi,

    You can do this by simply changing your connecitonstring.

    Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ExcelData.xls;Extended Properties=Excel 8.0;

    Also use the OleDbConnection to connect to an excel file. Just tweak with it and see the values it returns..

    Here's a link for additional info:
    http://support.microsoft.com/default.aspx?scid=kb;en-us;311731

     

    cheers,

    Paul June A. Domag

    Thursday, September 29, 2005 2:31 AM
  • Hi,

    You will define your myRange1 variable in excel itself. In my link provided look at the Create Sample Excel Worksheet steps. There you can see how to defing a name for your range to use in the sql statements.

    BTW, this is a strictly english forum. So you must post your question in english to ensure everyone here understands the question. Thanks.

     

    cheers,

    Paul June A. Domag

    Friday, September 30, 2005 12:55 AM

All replies

  • Hi,

    You can do this by simply changing your connecitonstring.

    Provider=Microsoft.Jet.OLEDB.4.0;Data Source=ExcelData.xls;Extended Properties=Excel 8.0;

    Also use the OleDbConnection to connect to an excel file. Just tweak with it and see the values it returns..

    Here's a link for additional info:
    http://support.microsoft.com/default.aspx?scid=kb;en-us;311731

     

    cheers,

    Paul June A. Domag

    Thursday, September 29, 2005 2:31 AM
  • El motor de base de datos Microsoft Jet no pudo encontrar el objeto 'myRange1'. Asegúrese de que el objeto existe, y que ha escrito el nombre y la ruta de acceso al objeto correctamente.


    Where can I define myRange1???



    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim str As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\levalencia\Mis documentos\Libro1.xls;Extended Properties=Excel 8.0"

     

    Dim objConn As New OleDbConnection(str)

    Try

     

    objConn.Open()

    Dim objCmdSelect As New OleDbCommand("SELECT * FROM myRange1", objConn)

    ' Create new OleDbDataAdapter that is used to build a DataSet

     

    ' based on the preceding SQL SELECT statement.

     

    Dim objAdapter1 As New OleDbDataAdapter()

    ' Pass the Select command to the adapter.

     

    objAdapter1.SelectCommand = objCmdSelect

    ' Create new DataSet to hold information from the worksheet.

     

    Dim objDataset1 As New DataSet()

    ' Fill the DataSet with the information from the worksheet.

     

    objAdapter1.Fill(objDataset1, "XLData")

    GridView1.DataSource = objDataset1

    GridView1.DataBind()

    Catch ex As Exception

    Label1.Text = ex.Message

    Finally

     

    objConn.Close()

    End Try

     

    End Sub


     

    Thursday, September 29, 2005 2:00 PM
  • Hi,

    You will define your myRange1 variable in excel itself. In my link provided look at the Create Sample Excel Worksheet steps. There you can see how to defing a name for your range to use in the sql statements.

    BTW, this is a strictly english forum. So you must post your question in english to ensure everyone here understands the question. Thanks.

     

    cheers,

    Paul June A. Domag

    Friday, September 30, 2005 12:55 AM
  •  Hi Luis,

     Look at  this url:

     Will solve all your problems,

     Nos vemos, Juan.

     

     

    Tuesday, January 10, 2006 6:08 PM