数据库链接是用dataset链接access的,table 只有帐户(name)和密码(password). 就是读不出来。。
private bool ValidateNow(string un, string pwd)
{
foreach (DataRow dr in tableDataSet.Tables["table"].Rows)
{
string oun = dr["name"].ToString();
string opwd = dr["password"].ToString();
if (oun == un && opwd == pwd)
return true;
}
return false;
}
private void button1_Click(object sender, EventArgs e) {
if (ValidateNow(textBox1.Text, textBox2.Text)) {
MessageBox.Show("成功");
} else {
MessageBox.Show("失败");
Application.Exit();
}
} }
private bool ValidateNow(string un, string pwd)
{
foreach (DataRow dr in tableDataSet.Tables["table"].Rows)
{
string oun = dr["name"].ToString();
string opwd = dr["password"].ToString();
if (oun == un && opwd == pwd)
return true;
}
return false;
}
private void button1_Click(object sender, EventArgs e) {
if (ValidateNow(textBox1.Text, textBox2.Text)) {
MessageBox.Show("成功");
} else {
MessageBox.Show("失败");
Application.Exit();
}
} }
select [name], [password] from yourTable
msgshow出来看一下,比如un或pwd是不是多了空格.
解决方法如Knight94所说..这样的问题第一次遇到确实会有点晕..^^
connect.open()
有没有这句
_conn.Open();
string strSQL = "select [name],[password] from Table"
OleDbCommand _comm = new OleDbCommand( strSQL, _conn);
DataTable dtDATA = new DataTable();
try
{
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = _comm;
da.Fill( dtDATA );
}
catch( Exception Message )
{
抛出异常;
}你可以先绑到DataGrid中看是否成功,来测试一下
DataGrid.DataSource = dtDATA;
DataGrid.DataBind();