Solved

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

Posted on 2004-09-21
4
679 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
[X]
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
4 Comments
 
LVL 11

Expert Comment

by:Agarici
ID: 12120479
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
ID: 12123769
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
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);
da.SelectCommand.ExecuteNonQuery();
cn.Close();
0
 
LVL 11

Accepted Solution

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


hth.A.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

628 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