«

»

Mar 07

how to load data from notepad to richtextbox using c#.net

I this article i am going to explain how to data from notepad to richtext box using c#.Net

[code language=”csharp”]

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.IO;

using System.Data.SqlClient;

namespace loadtxt

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

SqlConnection con = new SqlConnection("uid=sa;password=123;database=naseer");

private void button1_Click(object sender, EventArgs e)

{

string notepad = @"C:UsersNaseerDesktopsample.txt";

StringBuilder sb = new StringBuilder();

using (StreamReader sr = new StreamReader(notepad))

{

while (sr.Peek() >= 0)

{

sb.Append(sr.ReadLine());

}

}

string s = sb.ToString();

richTextBox1.Text = s.ToString();

string send = "insert into text values(‘"+richTextBox1.Text+"’)";

SqlCommand cmd = new SqlCommand(send,con);

con.Open();

cmd.ExecuteNonQuery();

MessageBox.Show("entered succesfully");

con.Close();

}

}

}

[/code]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>