Solved

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

Posted on 2004-09-21
4
672 Views
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.....

127.0.0.1        MyComputer
129.0.1.8        Server
0
Comment
Question by:kvnsdr
  • 2
  • 2
4 Comments
 
LVL 11

Expert Comment

by:Agarici
Comment Utility
sqlconnection c = new sqlconnection(...);
sqlcommand cmd = new sqlcommand();
c.Open();
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);
 cmd.executenonquery()
}



A.
0
 
LVL 1

Author Comment

by:kvnsdr
Comment Utility
I receive the following compile error: cannot convert type string to char

The following code is underlined.....

{Environment.NewLine} );
               
0
 
LVL 1

Author Comment

by:kvnsdr
Comment Utility
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);
da.SelectCommand.ExecuteNonQuery();
cn.Close();
0
 
LVL 11

Accepted Solution

by:
Agarici earned 250 total points
Comment Utility
then use
string[] lines = yourTextBox.Text.split( new char[]{'\n'} );


hth.A.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now