形式1
public void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.\ALLENSQL;Initial Catalog=TITOMSLogin;Integrated Security=True");
SqlDataAdapter sdf = new SqlDataAdapter("select usertype, fullname, position from login where username= '" + txtuser.Text + "' and password='" + txtpass.Text + "'", con);
DataTable dt = new DataTable();
sdf.Fill(dt);
string fullname = dt.Rows[0]["FullName"].ToString();
string position = dt.Rows[0]["Position"].ToString();
if (dt.Rows.Count == 1)
{
this.Hide();
if (dt.Rows[0]["Usertype"].ToString() == "Admin")
{
Form2Admin ss = new Form2Admin(position + ": " + fullname);
Form3Admin sa = new Form3Admin(position + ": " + fullname);
Form5 sw = new Form5(position + ": " + fullname);
ss.Show();
sa.Hide();
sw.Hide();
}
现在此代码无法以其他形式使用
private void button2_Click(object sender, EventArgs e)
{
this.Hide();
Form3Admin.Show();
}
这是我要实现的方案:
形式为1 public void button1_Click(对象发送者,EventArgs e){SqlConnection con =新的SqlConnection(@“ Data Source =。\ ALLENSQL; Initial Catalog = TITOMSLogin; Integrated Security = ...
您必须使用相同的实际Form3Admin
实例来显示它。将Form3Admin sa
实例保留为类变量,并在要显示它时使用该实例。