473,396 Members | 1,895 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,396 software developers and data experts.

code in c# to read data from csv file and put in sql server 2005

I have a csv file and it contains 4 columns which contain ip address of world.
example :
the colms are :
starting ip, endip, country code and country name ,
starting ip contains ip address like 200.1.3.4 same in end ip also

now the coloums in sql are
id , startip_1, startip_2.......startip_6 , endip_1, endip_2.....endip_6, country code, country name .

now i want to select the 1 by 1 row from csv file and store data in sql , something like 200.1.2.3 should be send to sql like 200 to startip_1, 1to startip_2....... and so ....hope u r getting what i want .

I am new to C# .. please give me the code and help me by providing solution step by step ..i m using sql server 2005 and C# 2005

startip_5, startip_6 and endip_5 and end_6 r null in sql rest all r not null .

please if anyone can give me solution to this on today itself ... it urgent...

thnk you.
Jul 23 '07 #1
4 2199
kenobewan
4,871 Expert 4TB
Data Transformation Services (DTS) allows you to import and export data from and to data sources (such as Microsoft Excel) that use an OLE DB provider. DTS replaces the Access import and export functions and also provides functions to: Export and import data to and from another SQL Server; export and import data to and from various formats such as Excel (XLS), Comma-Separated Values (CSV), and Microsoft Access; and, perform transformations on data. HTH.
Jul 23 '07 #2
RoninZA
78
Kenobewan - although DTS would be a handy way to import data from csv files into SQL, not all versions of SQL Server include DTS, such as MSDE.

82, what I would suggest is to open your file using a System.IO.StreamReader, with reference to the path of your file. Use the StreamReader.ReadLine method to read a line from your file into a string, and parse the string using the string.Split('') method, to break it up into the data sections you need.

These can then be easily inserted into a SQL table.

Hope it helps!
Jul 23 '07 #3
Plater
7,872 Expert 4TB
DTS is a free download addon.
But yes, if you want to do in-application transfer then reading in the file and parsing it would be correct.

Kenobewan - although DTS would be a handy way to import data from csv files into SQL, not all versions of SQL Server include DTS, such as MSDE.

82, what I would suggest is to open your file using a System.IO.StreamReader, with reference to the path of your file. Use the StreamReader.ReadLine method to read a line from your file into a string, and parse the string using the string.Split('') method, to break it up into the data sections you need.

These can then be easily inserted into a SQL table.

Hope it helps!
Jul 23 '07 #4
[quote=RoninZA]Kenobewan - although DTS would be a handy way to import data from csv files into SQL, not all versions of SQL Server include DTS, such as MSDE.

82, what I would suggest is to open your file using a System.IO.StreamReader, with reference to the path of your file. Use the StreamReader.ReadLine method to read a line from your file into a string, and parse the string using the string.Split('') method, to break it up into the data sections you need.

These can then be easily inserted into a SQL table.

Hope it helps![/QUOfghTE]

sdfsgdgdgdgdgdgdgdgdgdgdgdgdgdgd
Jul 26 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

38
by: jrlen balane | last post by:
basically what the code does is transmit data to a hardware and then receive data that the hardware will transmit. import serial import string import time from struct import * ser =...
18
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE)...
1
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
14
by: Mark Broadbent | last post by:
Does anybody know what is (factual please -not just guess) the quickest method to read data from a file? I am not interested in the format of the data (i.e. blocks, bytes, string etc) just that the...
6
by: Paolo Pignatelli | last post by:
I have an aspx code behind page that goes something like this in the HTML view: <asp:HyperLink id=HyperLink1 runat="server" NavigateUrl='<%#"mailto:" &amp;...
5
by: Zenek | last post by:
Hello, I have: - server MS SQL MSDE (2000) - database 'COLLBASE' - table 'MAIN' - row: column 'NAME' value 'version' and column 'VALUE' value '003' I make backup files by SQL query.
4
by: georges the man | last post by:
hey guys, i ve been posting for the last week trying to understand some stuff about c and reading but unfortunaly i couldnt do this. i have to write the following code. this will be the last...
53
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code,...
1
by: cnixuser | last post by:
Hello, I am having a problem that I believe is related to the way a stream reader object looks for a text file by default. What I am doing is using a StreamReader object to read the text of a text...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.