gpt4 book ai didi

C# 和 Oracle,登录表单 : Operation is not valid due to the current state of the object

转载 作者:行者123 更新时间:2023-11-30 19:57:22 25 4
gpt4 key购买 nike

  private void bLogIn(object sender, EventArgs e)
{

string logging = "select * from CLIENT where LOGIN='" + this.t_Login.Text + "' and PASSWORD='" + this.t_Password.Text + "' ;";

OracleConnection conn = new OracleConnection("Data Source=XXX/orcl;User Id=XXX;Password=XXX;");
OracleCommand cmd = new OracleCommand();

cmd.CommandText = logging;
cmd.Connection = conn;
try
{
conn.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}



int count = 0;

OracleDataReader reader = cmd.ExecuteReader(); // At this line there is the error: Operation is not valid due to the current state of the object

while (reader.Read())
{
count = count + 1;
}
if (count == 1)
{
MessageBox.Show("Welcome");
}
else
{
MessageBox.Show("Wrong Password");
}
conn.Dispose();
}

这是适用于 MySQL 的代码,但在转换为 Oracle 后就无法使用了。我究竟做错了什么?哪里不一样了。应该和 MySQL 一样简单吧?

为什么“OracleDataReader reader = cmd.ExecuteReader();”导致错误:“由于对象的当前状态,操作无效”???

最佳答案

您没有将连接分配给 cmd.. 尝试下面的代码

OracleCommand cmd = new OracleCommand();
cmd.connection = conn;
cmd.CommandText = logging;
int count = 0;
OracleDataReader reader = cmd.ExecuteReader();

关于C# 和 Oracle,登录表单 : Operation is not valid due to the current state of the object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30290333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com