Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table in the database, and that table consists of 5 columns, in the 5th column there will be a number "139". That number will be updated from time to time. So in the database when i get 139 newly, i have to get the number in the same row which is in the 2nd column. and then i have to store value in one variable and compare it with the SQL database of another table.


The code i have tried is:-

static void Main(string[] args)
        {
            // Create the connection to the resource!
            // This is the connection, that is established and
            // will be available throughout this block.
            using (SqlConnection conn = new SqlConnection())
            {
                // Create the connectionString
                // Trusted Connection is used to denote that the connection uses Windows Authentication
                conn.ConnectionString = "Server=[(local)];Database=[ModelDB];Trusted_Connection=true";
                conn.Open();


                // Create the command
                SqlCommand command = new SqlCommand("SELECT Alarms.Text, Routetable.Latitude, Routetable.Longitude FROM Alarms INNER JOIN Routetable ON Alarms.Text=Routetable.Location;", conn);
               
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    Console.WriteLine("Text\t");
                    while (reader.Read())
                    {
                        Console.WriteLine(String.Format("{0} \t ",
                            reader[0]));
                    }
                }
                Console.WriteLine("Coordinates displayed!!");
                Console.ReadLine();
                Console.Clear();

            }
            // Final step, close the resources flush dispose them. ReadLine to prevent the console from closing.
            Console.ReadLine();
        }
    }
}

are there any suggestions?

How the value updates is as shown below:

http://postimg.org/image/rq6wbbw5b/
Posted
Updated 11-Mar-15 1:16am
v3
Comments
KaushalJB 11-Mar-15 6:42am    
You mean to say 139 would be updated to 140 on next update?
Krishna Chaitanya Bezawada 11-Mar-15 6:45am    
Nope. It wont update to 140. But after a minute or hour or day again one more row will be created with the same 139. The value will always be 139. but the other values in the other columns may change. but it will create new row every time with the same number.
KaushalJB 11-Mar-15 7:01am    
Update your question with a Scenario which include before and after view of SQL Table to get more clear what you are exactly looking for !
Kuthuparakkal 11-Mar-15 8:31am    
English has gotten worsen this much since....
KaushalJB 11-Mar-15 8:56am    
Why don't you use "EventTime" Column in WHERE Clause for recent updated/Added row and adding the 139 Column in that condition.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900