473,411 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

reg: Simple, Help me out

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



Jul 19 '05 #1
1 1470
Hi:
Tx for ur suggestions. But can it can be done. U got any code for that. Pls
let me know. Or is there any easy process, that if we give inout as .txt,
file automatically it'll dump into the database?

Waiting for ur reply.
Best regards,
RK

"David Waz..." <dl*@pickpro.com> wrote in message
news:PX*********************@newssvr11.news.prodig y.com...
your data has commas within the data, and that is making the task more
difficult.

you need to accommodate the commas in the data, and possible quotation marks in the data.
check out regular expressions, or try to read the data field at a time
instead of line at a time.

"Rama krishna" <rm*********@vertexcs.com> wrote in message
news:uP**************@TK2MSFTNGP12.phx.gbl...
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



Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Mark J. McGinty | last post by:
Greets, One site I've written allows the user to install an IE extension menu (not malware at all) by downloading/merging a short .REG file. Worked like a peach on Win2K Server, now that I...
5
by: Henok Girma | last post by:
Hello Gurus, I wanted to have a very simple, strict regular expression validator for a phone field. the only valid format is (XXX) XXX-XXXX where X is a digit I have the following but it always...
1
by: worzel | last post by:
Hi All, I am looking for a reg ex that will match email addresses withing <a href=mailto blah > links. Actually, I already crafted my own, but with a slight problem: <a...
1
by: dixie | last post by:
I have a .reg file that I need to run across a network. Currently, we run it for each logon on the network manually, which is not really working well as there are over a hundred users and they...
7
by: DraguVaso | last post by:
Hi, Does anybody knows how to run a *.reg-file silently on a computer? I need this to do automatic updates of my application without user-interaction. So I don't want the user to be asked a...
1
by: Anurag | last post by:
Hi, I have 2 related questions. DB2 UDB ESE v8.x (8.1 till 8.2 FP2 - all fixpaks included) on AIX 5.4.x _____________________________________________________________________________ (QUESTION 1)...
11
by: don | last post by:
I have a string from a clearcase cleartool ls command. /main/parallel_branch_1/release_branch_1.0/dbg_for_python/CHECKEDOUT from /main/parallel_branch_1/release_branch_1.0/4 I want to write a...
2
by: Phillip Vong | last post by:
I'm looking for a simple Reg Expression to validate a textbox where the text must in in .doc or .pdf or .tif. Thanks in advance. Phil
1
by: black_13 | last post by:
are there any python modules for manipulation of .reg files producted by the win32 prog "reg". thanks. black_13
6
by: LeWalrus | last post by:
Hi, I've written a reg exp for capturing a group of numbers from text files in the following format: -1.4326 s < 0.6758 s < 1.4334 s Any of the numbers can be positive or negative and the units...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.