C# 从数据库中选择 url 到 Web 控件

发布于 2024-10-09 11:16:50 字数 1273 浏览 4 评论 0原文

我正在尝试将 url 从数据库放入 webcontrol。
我创建了 4 个选项卡控件,每个选项卡控件由 webcontrol 组成;我想使用从数据库获取的网址:
第一个 url 放入 tab1(选项卡内的浏览器) 第二个 url 放入 tab2 ...

我该怎么做?

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

    }

I am trying to put the url from database to webcontrol.
I create 4 tab control each tab control 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();

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北斗星光 2024-10-16 11:16:50

尝试使用:

// 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;
    }
}

在循环之前,使用 4 WebBrowser 创建一个数组。
然后在循环中创建一个名为 count 的 int ,并使用类似以下内容的内容: Navigate(WebBrowserList[count],thisrow);

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文