开发者

c# select url from database to web control

I am trying to put the url from database to webcontrol.

I create 4 tab control each tab con开发者_如何学Ctrol consist of webcontrol; I want to use the url that I get from database:

first url put to tab1(browser inside tab) second url put to tab2 ...

How can i do it?

private void Form1_Load(object sender, EventArgs e)
    {
        string MyConString = "SERVER=192.168.0.78;" +
             "DATABASE=webboard;" +
             "UID=aimja;" +
             "PASSWORD=aimjawork;" +
             "charset=utf8;";
        MySqlConnection connection = new MySqlConnection(MyConString);
        MySqlCommand command = connection.CreateCommand();
        MySqlDataReader Reader;
        command.CommandText = "SELECT  url FROM `listweb` WHERE `url` IS NOT NULL AND ( `webbordkind` = 'เว็บท้องถิ่น' ) and `nourl`= 'n' order by province, amphore limit 4 ";
        connection.Open();
        Reader = command.ExecuteReader();


        string thisrow = "";
        string sumthisrow = "";
        while (Reader.Read())
        {
            thisrow = "";
            for (int i = 0; i < Reader.FieldCount; i++)
                thisrow +=  Reader.GetValue(i).ToString();

          //  System.IO.File.AppendAllText(@"C:\file.txt", thisrow + " " + Environment.NewLine);
            sumthisrow = sumthisrow + thisrow;



        }
        connection.Close();

    }


Try using :

// Navigates with given WebBrowser to the given URL if it is valid.
private static void Navigate(WebBrowser webBrowser1, String address)
{
    if (String.IsNullOrEmpty(address)) return;
    if (address.Equals("about:blank")) return;
    if (!address.StartsWith("http://") &&
        !address.StartsWith("https://"))
    {
        address = "http://" + address;
    }
    try
    {
        webBrowser1.Navigate(new Uri(address));
    }
    catch (System.UriFormatException)
    {
        return;
    }
}

And before your loop, create an array with your 4 WebBrowser. Then in you loop, create an int named count, and use something like : Navigate(WebBrowserList[count],thisrow);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜