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

vivek kulkarni132 reputationPosted Feb 25, 2009, 5:50 AM EST
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
shyam kumar15 reputationPosted Feb 25, 2009, 6:53 PM EST
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 kulkarni132 reputationPosted Feb 26, 2009, 12:01 AM EST
Hi,
As as alternative you can also try the Import/Export DTS wizard.
Vivek Kulkarni
MCP MCAD.Net
Vijaya KadiyalaRank #1,085 · 1.8K reputationPosted Mar 21, 2009, 9:21 AM EDT
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
Rohan Varekar26 reputationPosted Jun 24, 2009, 4:36 AM EDT
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