显示连接形式 [英] show form on connection
本文介绍了显示连接形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好的,这是我的连接代码
Okay this is my connection code
class myConnection
{
public static string datasource = "";
public static string initialcatalog = "";
public static string uid = "";
public static string pwd = "";
public static MySqlConnection GetConnection()
{
string str = "SERVER='" + datasource + "';DATABASE='" + initialcatalog + "';UID='" + uid + "';PASSWORD='" + pwd + "'";
MySqlConnection con = new MySqlConnection(str);
con.Open();
return con;
}
}
我似乎无法弄清楚如何使其显示Form2(如果它实际上已连接到数据库),我已经完成了此操作,但是我在脑海中完全空白,无法在Google上找到任何内容(我很讨厌搜索大声笑)
i cant seem to figure out how to make it Show form2 if it actually connects to the database, i have done this befor but im completely drawing a blank in my mind and i cant find anything on google (i suck at searching lol)
Any help would be apreciated
推荐答案
假设Form2是您希望显示的表单,并且您位于Form1中,则可以执行以下操作:
Assuming Form2 is the form you wish to show and you are in Form1, you could do this:
public partial class Form1 : Form
{
...
public void ShowForm2()
{
MySqlConnection connection = myConnection.GetConnection();
if (connection != null)
{
Form2 frm2 = new Form2();
frm2.Show();
// or
// frm2.ShowDialog();
}
}
...
}
注意-我假设您尚未发布所有的"myConnection"类,因此未进行验证.但这是您向用户显示另一种表单的方式
Note - I am assuming you haven''t posted all of your "myConnection" class and so didn''t verify that. But this is how you show another form to the user
这篇关于显示连接形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文