【发布时间】:2013-06-02 11:38:54
【问题描述】:
MySqlConnection con = new MySqlConnection("host=*;user=*;password=*;database=*;");
MySqlCommand cmd = new MySqlCommand("SELECT * FROM members WHERE username = '" + textBox2.Text + "' AND password = '" + textBox3.Text + "';");
cmd.Connection = con;
DataTable dt = new DataTable();
con.Open();
MySqlDataReader reader = cmd.ExecuteReader();
if (reader.Read() != false)
{
if (reader.IsDBNull(0) == true)
{
cmd.Connection.Close();
reader.Dispose();
cmd.Dispose();
MessageBox.Show("Oops!There was a problem!");
}
else
{
cmd.Connection.Close();
reader.Dispose();
cmd.Dispose();
this.Hide();
Main main = new Main();
main.Show();
MySqlCommand cmmd = new MySqlCommand("SELECT Pain FROM members WHERE username='" + textBox2.Text + "';");
cmmd.Connection = con;
con.Open();
MySqlDataReader read = cmmd.ExecuteReader();
if (read.Read())
{
if (read.GetDecimal(0) == 1)
{
MessageBox.Show("NO");
cmmd.Connection.Close();
read.Dispose();
cmmd.Dispose();
}
else
{
MessageBox.Show("YES");
cmmd.Connection.Close();
read.Dispose();
cmmd.Dispose();
}
}
}
else
{
MessageBox.Show("You Login Information is incorrect!");
}
我希望 C# 读取 PAIN 列,如果它等于 0 则显示消息 NO,如果等于 1 则显示消息 YES。pain 列是 INT 类型并且是第 8 列
【问题讨论】:
-
痛苦的列是一个 INT 类型 - 那么也许使用
GetInt32()? -
另外,这会报错吗?
-
不,现在很好,非常感谢 :)
标签: c# mysql if-statement decimal datareader