我想用FORM1做为登陆界面,进入到FORM2,但是总是出错;
cmd.Connection.Open();在这句提示 未将对象引用设置到对象的实例?
这是为什么呢?
FORM1的;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private System.Data.SqlClient.SqlConnection conn;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string sql = "select *from login where(number='" + textBox1.Text + "')and (passwd='" + textBox2.Text + "')";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Connection.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (!reader.Read())
{
MessageBox.Show("please input the right information", "error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
Form2 F2 = new Form2();
F2.Show();
}
cmd.Connection.Close();
}
}
}
而对于FORM2的我还没做.但是就是跳不出来FORM2的界面,请大虾们帮忙看下!谢谢了