connection - System.InvalidOperationException:“ExecuteReader:连接属性尚未初始化。”
问题描述
我是一个初学者并尝试登录,但它不起作用,我尝试了“使用”命令,我搜索并发现我可能需要在执行阅读器中建立连接。这是我得到的错误:
System.InvalidOperationException: 'ExecuteReader: Connection property has not been initialized.' on the line of code using (OleDbDataReader reader = Com.ExecuteReader()).
我写的代码:
Con.Open();
OleDbCommand Com = new OleDbCommand();
Com.CommandText = "Select * from Admin where s_id='" + textBox1 + "'and password='" + textBox4 + "' ";
using (OleDbDataReader reader = Com.ExecuteReader()) //the reader will rea the data comes from the query
{
{
int count = 0; //to count the number of values coming, to count if there is ID and pssword present once
while (reader.Read()) //gives boolean variable until it gives true, it will continue in loop.
{
count = count + 1;
}
if (count == 1)
{
MessageBox.Show("ID and password are correct");
}
if (count > 1)
{
MessageBox.Show("duplicate ID and password");
}
else
{
MessageBox.Show("ID and password are correct");
}
}
}
Con.Close();
}
}
很抱歉写的杂乱无章,这是我第一次。
解决方案
推荐阅读
- flutter - 使用 Dart 进行实时语音转录
- python - 如何使用 Telethon 获取传入电报消息的聊天或群组名称?
- flutter - 颤振 - 从底部到顶部的按钮动画
- java - Firestore 讲座操作计数
- python - 将长列表与数据框中的字符串进行比较,并在匹配的基础上填充 Python 中的数据框
- java - Recyclerview 没有第一次加载( Firebase )
- reactjs - React JS,显示来自嵌套 json 的数据
- javascript - 是否可以使用javascript获取屏幕颜色?
- c++ - Linux - 信号:错误:非静态成员函数的使用无效
- sql-server - SQL Server + Linux + VB6 + Wine + Adodb.Recordset +错误 430