c# - System.Data.OleDb.OleDbException:“没有为一个或多个必需参数提供值。” 一直显示
问题描述
你好我是这个网站的新手,我想知道如何从 MS Access 获取数据,它总是给我这个错误。
public partial class MainWindow : Form
{
OleDbConnection nc;
public MainWindow()
{
InitializeComponent();
nc = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\AfSMS\StudentManagementSystem\StudentManagementSystem\bin\Debug\MainStudData.accdb");
}
private void btnSearch_Click(object sender, EventArgs e)
{
nc.Open();
OleDbCommand gd = new OleDbCommand("Select StudID,S_Name,F_Name,Address,BoD,Mob_Num,Email FROM StudInfo WHERE StudID=@dg1", nc);
gd.Parameters.AddWithValue("@dg1", txtStud_ID.Text);
OleDbDataReader dtr1;
dtr1 = gd.ExecuteReader();
if (dtr1.Read())
{
txtStudID.Text = dtr1["StudID"].ToString();
txtS_Name.Text = dtr1["S_Name"].ToString();
txtF_Name.Text = dtr1["F_Name"].ToString();
txtAddress.Text = dtr1["Address"].ToString();
txtBoD.Text = dtr1["BoD"].ToString();
txtNum.Text = dtr1["Mob_Num"].ToString();
txtMail.Text = dtr1["Email"].ToString();
}
else
{
MessageBox.Show("Data not Found", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
nc.Close();
}
解决方案
推荐阅读
- django - 如何在 django 模板中设置图像路径
- ionic-framework - 如何在启动时加载所有页面?
- unity3d - Firebase 数据库检索用户的高分排名
- python - 如何在 Python 中更新字典中键字段的值?
- python - 在 Keras Sequential 模型中,Conv2D 似乎要求内核比前一层厚。为什么?
- matlab - 使用优化工具箱时如何解决“数组索引必须是正整数或逻辑值”?
- python-3.x - 从所有列中具有“无”值的数据框中删除行 - Python
- javascript - 路由器链接配置的目标不生成 html 代码
- arrays - 如何快速使用 Ms SQL 查询结果填充数组?
- c# - 当我使用 range.find 使用 vsto 搜索整个文档时,如何跳过表格?