How to set a trigger point in SQL

Setting trigger point in SQL to load new data

Page 1 of 1

6 Replies - 1150 Views - Last Post: 28 October 2010 - 11:26 AM Rate Topic: -----

#1 srinivasks33  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 26-October 10

How to set a trigger point in SQL

Posted 27 October 2010 - 11:24 AM

Hi,

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


Is This A Good Question/Topic? 0
  • +

Replies To: How to set a trigger point in SQL

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: How to set a trigger point in SQL

Posted 27 October 2010 - 11:26 AM

How many times will you need to be told to USE CODE TAGS when posting code???

:code:
Was This Post Helpful? 0
  • +
  • -

#3 srinivasks33  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 26-October 10

Re: How to set a trigger point in SQL

Posted 28 October 2010 - 10:32 AM

Hi,

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();

}



Was This Post Helpful? 0
  • +
  • -

#4 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: How to set a trigger point in SQL

Posted 28 October 2010 - 10:36 AM

Could we see the code for displaying your data you have so far?
Was This Post Helpful? 0
  • +
  • -

#5 srinivasks33  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 26-October 10

Re: How to set a trigger point in SQL

Posted 28 October 2010 - 10:53 AM

View PostFlashM, on 28 October 2010 - 09:36 AM, said:

Could we see the code for displaying your data you have so far?

Hi thanks for your reply..The below code shows how it is displayed.


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;

            }
        }


Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: How to set a trigger point in SQL

Posted 28 October 2010 - 11:06 AM

Merged duplicate topics. Please do NOT create a new topic when you already HAVE a topic on the same subject.
Was This Post Helpful? 0
  • +
  • -

#7 srinivasks33  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 26-October 10

Re: How to set a trigger point in SQL

Posted 28 October 2010 - 11:26 AM

View PostJackOfAllTrades, on 27 October 2010 - 10:26 AM, said:

How many times will you need to be told to USE CODE TAGS when posting code???

:code:

Hi,

I did use the TAGS this time...

View PostJackOfAllTrades, on 28 October 2010 - 10:06 AM, said:

Merged duplicate topics. Please do NOT create a new topic when you already HAVE a topic on the same subject.


Hi,

I had to change the Topic description so I created a new post... Sorry if that is not allowed...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1