求助,为何编译时报错——数据库问题
//这窗口程序是一个登录界面。登录的用户存在Users 表里但是当输入用户名和密码时都提示SqlDataReader myDataReader = myCommand.ExecuteReader();地方有错。
谁能帮我看下程序
public partial class LogForm : Form
{
MainForm mainForm;
public LogForm(MainForm pFrom)
{
InitializeComponent();
mainForm = pFrom;
if (mainForm.myConnection.State == System.Data.ConnectionState.Closed)
{
MessageBox.Show("出错不能登录");
this.Text = "登录数据库失败,请退出检查与数据库的连接";
this.buttonNew.Enabled = false;
this.buttonNew.Enabled = false;
}
}
private void buttonLogon_Click(object sender, EventArgs e)
{
String commandstring = "SELECT * FORM Users";
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = mainForm.myConnection;
= commandstring;
SqlDataReader myDataReader = myCommand.ExecuteReader();
bool b_accepted = false;
while(myDataReader.Read())
{
if(myDataReader.GetString(0).Trim() == textBox1.Text.Trim() && myDataReader.GetString(1).Trim() == textBox2.Text.Trim())
{
b_accepted = true ;
break;
}
}
if(b_accepted == false)
{
MessageBox.Show("输入有错,请重新输入");
}
else
{
mainForm.currentUser = this.textBox1.Text.Trim();
this.Close();
}
}
private void buttonQuit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void buttonNew_Click(object sender, EventArgs e)
{
}
}