Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


C#: Parse textBox1.text into SQL datatable then reverse the procedure later......????

Posted on 2004-09-21
Medium Priority
Last Modified: 2011-10-03
I need to parse the contents of a textbox into a SQL datatable then at a later time parse the SQL table back into the textbox. The textbox contents look like the following. It is very similar to a hosts file in content and structure. The data contents are seperated by a 'tab' and lines seperated by 'newline' or linefeed.....        MyComputer        Server
Question by:kvnsdr
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 11

Expert Comment

ID: 12120479
sqlconnection c = new sqlconnection(...);
sqlcommand cmd = new sqlcommand();
cmd.Connection = c;

string[] lines = yourTextBox.Text.split( new char[]{Environement.NewLine} );
foreach( string line in lines )
 string[] lineParts = line.split(new char[]{'\t'} );
 // now use lineParts[0] - ip addr and lineParts[1] - computer name to insert/update the sql datatable
 cmd.CommandText = string.Format("Insert into computers( IP, NAME ) values ( '{0}', '{1}' ) ", lineparts[0],lineparts[1);


Author Comment

ID: 12123769
I receive the following compile error: cannot convert type string to char

The following code is underlined.....

{Environment.NewLine} );

Author Comment

ID: 12123877
I also use the following 'hand-coded' SQL connection syntax:

string SQL = " SELECT * FROM tbl_Ports ";
SqlConnection cn = new SqlConnection("integrated security=SSPI;data source=office; persist security info=False;initial catalog=master ");
SqlDataAdapter da = new SqlDataAdapter(SQL,cn);
LVL 11

Accepted Solution

Agarici earned 750 total points
ID: 12130765
then use
string[] lines = yourTextBox.Text.split( new char[]{'\n'} );


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question