Loading ...

HowToImportExcelDataToMYSQL

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  data access   » HowToImportExcelDataToMYSQL

HowToImportExcelDataToMYSQL

Posts under the topic: HowToImportExcelDataToMYSQL

Posted: 8/2/2010

Lurker 15  points  Lurker
  • Joined on: 7/24/2010
  • Posts: 3

Since in MYSQL we dont hav any "Open datasource" statements, i hav tried using those statement in asp.code. My only doubt is, its getting executed fine without any errors but the value i m storing in dataset is not getting stored in db when i update it in db using dataadapter. Plz just take a look at my code and help me where i m making wrong.

Dim xlsDA As New OleDbDataAdapter()
        Dim xlsDS As New Data.DataSet()
        If Path.GetExtension(uploadFile).ToLower = ".xls" Then
            FileExport.PostedFile.SaveAs(Server.MapPath("\logsw") + "\" + uploadFile)
            uploadFile = Server.MapPath("\logsw") + "\" + uploadFile
            Dim xlsCon As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + uploadFile + ";Extended Properties=Excel 8.0;Mode=12;")
            xlsCon.Open()
            Dim xlsCmd As New OleDbCommand("SELECT * FROM [Sheet1$]", xlsCon)
            xlsDA.SelectCommand = xlsCmd
            xlsDA.Fill(xlsDS)
            xlsCon.Close()
        End If

        Dim insCon As New OdbcConnection(Web.Configuration.WebConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim insDA As New OdbcDataAdapter()
        Dim insDS As New Data.DataSet
        insDS = xlsDS
        insDA.Update(insDS)


Posted: 9/3/2010

Lurker 55  points  Lurker
  • Joined on: 10/22/2009
  • Posts: 7
  Answered

Dim insCon As New OdbcConnection(Web.Configuration.WebConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim insDA As New OdbcDataAdapter()

Dim sqlCmd As OdbcCommand("SELECT * FROM Table1 where 1=2", insCon)    'only copy structure of table in your MySql database

insDA .SelectCommand = sqlCmd

   Dim insDS As New Data.DataSet
            insDA .Fill(insDS)

DataRow newDr;

For Each
DataRow dr In xlsDS.Tables[0].Rows
newDr=insDS.Tables[0].NewRow
newDr[0]=dr[0]
newDr[1]=dr[1]
........
.....
..
insDS.Tables[0].Rows.Add( newDr[0])

Next

insDA.Update(insDS)

There may be some syntax errors, Do not get confused.

I am not such familiar with Vb.net , I am trying to give you right approch.

 

Thanks

 


Posted: 9/16/2010

Lurker 80  points  Lurker
  • Joined on: 9/14/2010
  • Posts: 8

hi rathi priya,

                   here is the link to import excel data to sql database

http://aspdotnet-suresh.blogspot.com/2010/09/import-data-from-excel-to-sql-database.html


Page 1 of 1 (3 items)