日期:2014-05-18  浏览次数:20665 次

求解问题说是“至少一个参数没有被指定值”!!
private void button1_Click_1(object sender, EventArgs e)
  {
  if (textBox1.Text == ""||textBox2.Text=="")
  {
  MessageBox.Show("请输入账号和密码");
  }
  else
  {
  OleDbConnection conn = new OleDbConnection();
  conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\Access2003\db1.mdb";
  conn.Open();
  string sql = "select [user].* from [user] where id='" + textBox1.Text + "'and ps='" + textBox2.Text + "'";
  OleDbCommand cmd = new OleDbCommand(sql, conn);
  OleDbDataReader dr=cmd.ExecuteReader();
  if (dr.Read())
  {
  主窗口 f3 = new 主窗口();
  f3.Show();
  this.Hide();
  }  
  else
  {
  MessageBox.Show("用户名或密码不正确!");
  }
  dr.Close();
  conn.Close();

------解决方案--------------------
id是什么类型的字段?如果不是字符型的话两边的单引号要去掉。
------解决方案--------------------
id和ps两边加上[]:
string sql = "select [user].* from [user] where [id]=" + textBox1.Text + " and [ps]='" + textBox2.Text + "'";
------解决方案--------------------
现在问题肯定出在sql语句,你可以先在Access中把sql语句写好,运行正确了再写C#代码。