I'm developing a application using a windows form application using C# and SQL server database. As soon as the form is loaded I do display 500 rows of data on the screen I use richTextbox to display the data. The data is simple message in each row.
Now I wanted to set a trigger point in SQL in such way that if the user scrolls past a certain scroll position i.e after 300 rows I need to add the recent 300 rows of data from the database and display it and the same case if the user moves up the richtextbox should be loaded with old 300 rows of data. Any help is appreciated as I'm struggling a lot to sort out this issue.
I will be receiving the communication continuosly from the Serial port so there is always a new data in the SQL server database.
My code to insert data into database is as follows:
private void TerminalForm_Load(object sender, EventArgs e)
{
SqlConnection con;
SqlCommand cmd;
SqlDataAdapter sda;
string qry = "";
qry = "INSERT INTO [Example].[dbo].[SystemConsole1]([time],[Message])VALUES(GETDATE(),'" + rtTerminal.Text + "')";
con = new SqlConnection("Data Source=SRINIVAS-PC\\SQLEXPRESS;Database=SystemConsole;Trusted_Connection=True");
cmd = new SqlCommand(qry, con);
if (con.State == ConnectionState.Open)
con.Close();
else
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
To display the data from the database I use following code:
private void rtTerminal_keyDown(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=YOUR-0Z71CK0XVX\\SQLEXPRESS;Initial Catalog=Example;Integrated Security=True");
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(
"SELECT TOP 500 (Message) from Example.dbo.logFile order by Time desc", conn);
adapter.Fill(ds);
foreach (DataRow row in ds.Tables[0].Rows)
{
for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
rtTerminal.Text += row[i].ToString() + Environment.NewLine;
rtTerminal.Text += Environment.NewLine;
}
}
Where rtTerminal is the richtextbox which I use to display the data from the database. Could anyone please advice me how I can set a "High" and "Low" trigger points in order to refresh the data.. Any help is appreciated in advance..
This post has been edited by JackOfAllTrades: 27 October 2010 - 11:27 AM
Reason for edit:: Added code tags

New Topic/Question
Reply




MultiQuote





|