guyz,
i have table called CSVTest which has ID int, First name char(50) fields. Then i have a text file called csv.txt in my C:\ drive. The csv.txt contains
1,sk
2,test
3,test2
i tried to do a bulk insert but it failed and the error message is unable tofind the file.
Now guyz i want to insert the csv data into my sql server using either sql query or VB.Net code
please help me
thank in advance
sk
Loading
Rohan VarekarPosted Jun 24, 2009, 8:36 AM
To Save that file on server u this
On Button click------------
strFileName = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("\") + 1)
strFileType = File1.PostedFile.ContentType
intFileSize = File1.PostedFile.ContentLength
If intFileSize <= 0 Then
' Response.Write(" Uploading of file " + strFileName + " failed ")
lblError.Text = "Select the Input File First"
Else
lblError.Text = "File Processing ....."
File1.PostedFile.SaveAs(Server.MapPath("InputFile" + "\\" + strFileName))
End If
Call ProcessInputFile()
Sub ProcessInputFile()
Dim ArrForScanItem() As String
dim str1,Str2,str3 as string
count = 0
InputFilePath = New StreamReader(Server.MapPath("InputFile" + "\\" + strFileName))
lblError.Text = "File Processing ........."
While (1)
InputLine = InputFilePath.ReadLine
If InputLine = "" Then
Exit While
End If
ArrForScanItem = InputLine.Split(",")
Try
str1= ArrForScanItem(0)
str2 = ArrForScanItem(1)
str3 = ArrForScanItem(2)
Call InsertData() '''Here u write ur code to insert data wht u want to insert
Catch es As Exception
lblError.Text = strSearchCode + " : Error in Input File."
lblError.Text &= es.Message
End Try
End While
InputFilePath.Close()
End Sub
Vijaya KadiyalaPosted Mar 21, 2009, 1:21 PM
Hi
Check out the below link
http://blog.sqlauthority.com/2008/02/06/sql-server-import-csv-file-into-sql-server-using-bulk-insert-load-comma-delimited-file-into-sql-server/
Thanks -- Vijaya Kadiyala
http://dotnetvj.blogspot.com
vivek kulkarniPosted Feb 26, 2009, 5:01 AM
Hi,
As as alternative you can also try the Import/Export DTS wizard.
Vivek Kulkarni
MCP MCAD.Net
shyam kumarPosted Feb 25, 2009, 11:53 PM
hello vivek,
tha bulk insert command give me an error
Cannot bulk load. The file "C:\csvtest.txt" does not exist.
i am using Sql server 2008 standard edition.
still no luck
regards
shyam
vivek kulkarniPosted Feb 25, 2009, 10:50 AM
Hi,
Please can you give me the sql that you were trying.
Here is the link
http://msdn.microsoft.com/en-us/library/ms188365.aspx
BULK INSERT tmpStList FROM 'c:\TxtFile2.txt' WITH (FIELDTERMINATOR = ',')
Thank you,
Vivek Kulkarni
MCP MCAD.Net