R
Rama krishna
Hi All:
I got a .txt file with five columns, it's named as in the first line with
double quotes of each column. And from the second line onwards, the real
data. So i would like keep the these data in their corresponding columns in
the sql database. I created a table with these 5 columns in the database,
now i want these data to be dumped into database. So initially iam trying to
read line by line, and spliting using "" as a delimiter. But am not able to
do it. Iam sending my code along with this data, pls help me out.
"Activity Name","Start Date","Finish Date","Resources Assigned","Notes per
Bar"
"HLD","7/2/03","7/30/03",,
"Interal Design","7/2/03","7/3/03","RamaKrishna, Kittu","hai"
"Interal Design of ATP","7/8/03","7/9/03","RamaKrishna, Richard",
"Sign-Off","7/9/03","7/9/03","RamaKrishna",
Dim objReader As New StreamReader("c:\TestData.txt")
'Inserting ProjectData into SQL Database
Dim cnDBConnection As New SqlConnection("Data Source=goutham;
Database=pubs;User ID=sa;Pwd=sa")
cnDBConnection.Open()
Dim sqlInsertCommand As New SqlCommand()
While objReader.Peek > -1
str = objReader.ReadLine
'Response.Write(str & "<br>")
strSplit = Split(str, """")
For i = 1 To UBound(strSplit) - 1
'Response.Write(strSplit(i) & "<br>")
arrStrColumnNamesAfterNew = Split(strSplit(i), ",")
Next
sqlInsertCommand.CommandText = "Insert into ProjectData([Activity
Name],[Start Date],[Finish Date],[Resources Assigned],[Notes Per Bar])
values('" & arrStrColumnNamesAfterNew(0) & "', '" &
arrStrColumnNamesAfterNew(1) & "' , '" & arrStrColumnNamesAfterNew(2) & "' ,
'" & arrStrColumnNamesAfterNew(3) & "',, '" & arrStrColumnNamesAfterNew(4) &
"')"
sqlInsertCommand.Connection = cnDBConnection
sqlInsertCommand.ExecuteNonQuery()
Pls help me out.
Waiting for ur reply.
Best regards,
RK
I got a .txt file with five columns, it's named as in the first line with
double quotes of each column. And from the second line onwards, the real
data. So i would like keep the these data in their corresponding columns in
the sql database. I created a table with these 5 columns in the database,
now i want these data to be dumped into database. So initially iam trying to
read line by line, and spliting using "" as a delimiter. But am not able to
do it. Iam sending my code along with this data, pls help me out.
"Activity Name","Start Date","Finish Date","Resources Assigned","Notes per
Bar"
"HLD","7/2/03","7/30/03",,
"Interal Design","7/2/03","7/3/03","RamaKrishna, Kittu","hai"
"Interal Design of ATP","7/8/03","7/9/03","RamaKrishna, Richard",
"Sign-Off","7/9/03","7/9/03","RamaKrishna",
Dim objReader As New StreamReader("c:\TestData.txt")
'Inserting ProjectData into SQL Database
Dim cnDBConnection As New SqlConnection("Data Source=goutham;
Database=pubs;User ID=sa;Pwd=sa")
cnDBConnection.Open()
Dim sqlInsertCommand As New SqlCommand()
While objReader.Peek > -1
str = objReader.ReadLine
'Response.Write(str & "<br>")
strSplit = Split(str, """")
For i = 1 To UBound(strSplit) - 1
'Response.Write(strSplit(i) & "<br>")
arrStrColumnNamesAfterNew = Split(strSplit(i), ",")
Next
sqlInsertCommand.CommandText = "Insert into ProjectData([Activity
Name],[Start Date],[Finish Date],[Resources Assigned],[Notes Per Bar])
values('" & arrStrColumnNamesAfterNew(0) & "', '" &
arrStrColumnNamesAfterNew(1) & "' , '" & arrStrColumnNamesAfterNew(2) & "' ,
'" & arrStrColumnNamesAfterNew(3) & "',, '" & arrStrColumnNamesAfterNew(4) &
"')"
sqlInsertCommand.Connection = cnDBConnection
sqlInsertCommand.ExecuteNonQuery()
Pls help me out.
Waiting for ur reply.
Best regards,
RK