mfazi
asked on
How to read CSV file
Hello,
Can some one tell me how i can read CSV file and store the information in SQl database.
My CSV file has this type of information
Physician_ID LastName FirstName MI
4 Ananth Uma
122 Baluch John D
97 Bing Arthur G
5 Bohl Robert D
My sql databse has same fields as these columns have.
please help me.
Thanks in advance
Can some one tell me how i can read CSV file and store the information in SQl database.
My CSV file has this type of information
Physician_ID LastName FirstName MI
4 Ananth Uma
122 Baluch John D
97 Bing Arthur G
5 Bohl Robert D
My sql databse has same fields as these columns have.
please help me.
Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or you could just write a DTS package if you are doing this over and over again with the same file
Checkout this link:
A Simplified SQL-CSV Import/Export Functionality
http://www.codeproject.com/aspnet/ImportExportCSV.asp
How To Read a CSV-text-file using VB.NET and save into SQL Server
http://www.dotnetspider.com/technology/kbpages/1082.aspx
HTH, Nauman.
A Simplified SQL-CSV Import/Export Functionality
http://www.codeproject.com/aspnet/ImportExportCSV.asp
How To Read a CSV-text-file using VB.NET and save into SQL Server
http://www.dotnetspider.com/technology/kbpages/1082.aspx
HTH, Nauman.
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.IO
Code :
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim intFileNameLength As Integer
Dim strFileNamePath As String
Dim strFileNameOnly As String
If Not (UploadFile.PostedFile Is Nothing) Then
strFileNamePath = UploadFile.PostedFile.File
intFileNameLength = InStr(1, StrReverse(strFileNamePath
strFileNameOnly = Mid(strFileNamePath, (Len(strFileNamePath) - intFileNameLength) + 2)
Dim paths = Server.MapPath("/excelread
paths = paths & "Excel/"
'If File.Exists(paths & strFileNameOnly) Then
'lblMessage.Text = "Image of Similar name already Exist,Choose other name"
'Else
If UploadFile.PostedFile.Cont
lblMessage.Text = "The Size of file is greater than 4 MB"
ElseIf strFileNameOnly = "" Then
Exit Sub
Else
strFileNameOnly = Session("AdminID") & "-" & Session("Acountry") & "-" & Format(Date.Today, "mm-dd-yyyy").Replace("/",
UploadFile.PostedFile.Save
lblMessage.Text = "File Upload Success."
Session("Img") = strFileNameOnly
End If
End If
'End If
Dim myDataset As New DataSet()
Dim strConn As String = "Provider=Microsoft.Jet.OL
"Data Source=" & Server.MapPath("/excelread
"Extended Properties=Excel 8.0;"
''You must use the $ after the object you reference in the spreadsheet
Dim myData As New OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn)
myData.TableMappings.Add("
myData.Fill(myDataset)
DataGrid1.DataSource = myDataset.Tables(0).Defaul
DataGrid1.DataBind()
End Sub
Private Sub btnExportToExcel_Click(ByV
' Set the content type to Excel.
Response.ContentType = "application/vnd.ms-excel"
' Remove the charset from the Content-Type header.
Response.Charset = ""
' Turn off the view state.
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWrit
' Get the HTML for the control.
DataGrid1.RenderControl(hw
' Write the HTML back to the browser.
Response.Write(tw.ToString
' End the response.
Response.End()
lblMessage.Text = "For any more information , feel free to contact ...!!!"
End Sub
Regards,
Aeros