C# 从数据库中选择 url 到 Web 控件
我正在尝试将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用:
在循环之前,使用 4 WebBrowser 创建一个数组。
然后在循环中创建一个名为 count 的 int ,并使用类似以下内容的内容:
Navigate(WebBrowserList[count],thisrow);
Try using :
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);