【发布时间】:2013-04-12 18:58:58
【问题描述】:
我正在尝试通过基于特定电子邮件选择记录来在我的 Windows 窗体上显示数据库内容。
我正在使用以下代码,但它没有检索到它
private void editrecordbutton_Click(object sender, EventArgs e)
{
MyOleDbConnection.Open();
string query = string.Format("select Email from login where Email='{0}'", editrecordtextBox.Text);
OleDbCommand vcom1 = new OleDbCommand(query, MyOleDbConnection.vcon);
OleDbDataReader reader = vcom1.ExecuteReader();
//int check = vcom1.ExecuteNonQuery();
string email = (string)reader["Email"];
if (email == editrecordtextBox.Text)
{
if (editrecordtextBox.Text != string.Empty)
{
EmailReturn = editrecordtextBox.Text;
FinalEdit er = new FinalEdit();
this.Close();
er.Show();
MyOleDbConnection.Close();
}
else
{
MessageBox.Show("No record selected");
}
}
else
{
MessageBox.Show("Invalid Email-Id");
}
MyOleDbConnection.Close();
}
请帮助我了解它有什么问题以及我是否以正确的方式看待这种方法。
【问题讨论】:
-
你调试过你的代码吗?
EmailReturn和FinalEdit类也是什么?并注意SQL Injection。 -
我希望我的电子邮件是
';drop table login; -
@spender 你邪恶! =)