Click here to Skip to main content
15,888,293 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have developed a c# Windows forms application, which will connect to SQL and execute an SQL Query and shows the output data in a Message Box only when the data got changed from the previous output. Now i have developed a new form in the same Project and added web browser to the new form. SO now i have stored the output values of SQL in 2 variables namely lati and longi. Now i have passed them to my new form.

And when i execute my browser with that "url + lati+ longi" valu its not returning any output. Atleast it is not opening any browser form also.

I have tried the following in form2:-

C#
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;

namespace LeakLocationFinder
{
    public partial class Maps : Form
    {
        public string lati;
        public string longi;
        public MainForm lat, lon;
        public Maps()
        {
            InitializeComponent();
        }
     

        private void Maps_Load(object sender, EventArgs e)
        {
            string url = "https://www.google.co.in/maps/place/";
            webBrowser1.Navigate(url + lati + "," + longi);
        }
    }
}


I have following in form 1:-

C#
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.Data.SqlClient;

namespace LeakLocationFinder
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }
        public void MainForm_Load(object sender, EventArgs e)
        {
                String old_value = "";
                while (true)
                {
                    String connetionString = null;
                    SqlConnection conn;
                    SqlCommand cmd;
                    String sql = null;
                    SqlDataReader reader;

                    connetionString = "server=(local);database=modelDb;user id=sa;pwd=Esi2008*";
                    sql = "DECLARE @var varchar(1000) = (SELECT TOP 1 Text FROM Alarms WHERE AlarmDefinitionId=139 ORDER BY EventTime DESC) DECLARE @start_position int, @end_position int SELECT @start_position = PATINDEX('% at%', @var) SELECT @end_position = PATINDEX('%kilometers%', @var) DECLARE @VALUE VARCHAR(10) = (Select SUBSTRING(@var, @start_position+5,5)) Select Top 1 @VALUE,RouteTable.Latitude,Routetable.Longitude,Alarms.ApplicationTime,RouteTable.StationName,RouteTable.SectionName FROM Alarms INNER JOIN Routetable ON Routetable.Location BETWEEN FLOOR(@VALUE)-1 AND CEILING(@VALUE)+1 WHERE AlarmDefinitionId=139 ORDER BY EventTime DESC";

                    conn = new SqlConnection(connetionString);
                    try
                    {
                        conn.Open();
                        cmd = new SqlCommand(sql, conn);
                        reader = cmd.ExecuteReader();
                        while (reader.Read())
                        {

                            if (old_value.ToString() != reader.GetValue(0).ToString())
                            {
                                MessageBox.Show("Leak Location:-" + "              " + reader.GetValue(0) + Environment.NewLine + "Latitude:-" + "                          " + reader.GetValue(1) + Environment.NewLine + "Longitude:-" + "                       " + reader.GetValue(2) + Environment.NewLine + "Leak Occured Time:-" + "       " + reader.GetValue(3) + Environment.NewLine + "Station Name:-" + "                 " + reader.GetValue(4) + Environment.NewLine + "Section Name:-" + "                " + reader.GetValue(5));
                                string lat = reader.GetValue(1).ToString();
                                string lon = reader.GetValue(2).ToString();
                                Maps form = new Maps();
                                {
                                    string lati = lat;
                                    string longi = lon;
                                };
                            }
                            else
                            {

                            }
                            old_value = reader.GetValue(0).ToString();
                       }
                        reader.Close();
                        cmd.Dispose();
                        conn.Close();
                    }
                    catch (Exception)
                    {
                      MessageBox.Show("Cannot Open Connection...! ");
                    }
                    System.Threading.Thread.Sleep(5 * 1000);
                }
            }
 
     private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            About_LeakLocationFinder formhelp = new About_LeakLocationFinder();
            formhelp.Show();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}


The url will be executed with url + lati value and longi value between lati and longi there will be a comma (",").
Please help
Posted
Updated 19-Apr-15 23:45pm
v2
Comments
Pikoh 20-Apr-15 6:06am    
Try adding a '@' before the lati,like:

webBrowser1.Navigate(url + "@" + lati + "," + longi);
Krishna Chaitanya Bezawada 20-Apr-15 6:09am    
Actually the form itself is not Displaying in System, the application is running in background in task manager for Main form. But 2nd form is not displaying at all.

you have to call
C#
form.Show()


C#
 Maps form = new Maps();
{
    string lati = lat;
    string longi = lon;
};
form.Show();
 
Share this answer
 
Comments
Krishna Chaitanya Bezawada 20-Apr-15 6:35am    
Yes, i have recognized my mistake and corrected it, Now its showing the Maps form. But it is not redirecting to the Web address which i have given. Its displaying a blank page and mouse cursor is in processing icon and its lasting for so many minutes.
Florian Braun 20-Apr-15 6:38am    
for debugging: try the generated url (url + lati + "," + longi) in a normal browser. Maybe google isn't happy with your generated url?
Krishna Chaitanya Bezawada 20-Apr-15 6:57am    
I have tried in the normal browser and it is working to be fine in the browser.
Not only that if i give there "http://www.google.com" also its not taking any url there. it is under loading mode only
Florian Braun 20-Apr-15 7:04am    
do you have an example url thats working in browser but not in your application?

I tried to do the same (without the sql stuff) and your code works fine here with a fixed url like "http://www.google.com".
Krishna Chaitanya Bezawada 20-Apr-15 7:35am    
Here also i have tried it with out SQL and all, but then also its not working, So i have tested in other systems too but there is no result.
use this code
C#
webBrowser1.Url = new Uri(url + lati + "," + longi);


instead of
C#
webBrowser1.Navigate(url + lati + "," + longi);
 
Share this answer
 
Comments
Krishna Chaitanya Bezawada 21-Apr-15 0:30am    
Its not Working.

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