我的代码背后有错误请跟踪我的问题..... oledbexception是适合的 [英] I have an error in code behind please trace my problem.....oledbexception are accoured

查看:46
本文介绍了我的代码背后有错误请跟踪我的问题..... oledbexception是适合的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此错误已发生

This Error was occoured

Quote:

System.Data.OleDb.OleDbException(0x80040E):无值给出一个或多个必需参数。

System.Data.OleDb.OleDbException(0x80040E): No Value given for one or more required parameter.





我尝试过:





What I have tried:

conn.Open();
string query1 = "select*from tblLoan where EmpsID like '" + textBoxEmpsID.Text + "%' And Starting_Month Like'" + comboBoxMonth.SelectedItem + "%' And Status Like'" + "A" + "%'";
DataTable dt = new DataTable();
OleDbDataAdapter dad = new OleDbDataAdapter(query1, conn);
dad.Fill(dt);
Installments.Text = dt.Rows[0][2].ToString();
Status.Text = dt.Rows[0][5].ToString();
LoanID.Text = dt.Rows[0][7].ToString();
conn.Close();

推荐答案

如果这是给出错误的代码,那很可能是因为你的文本框的内容或者你的组合:无论如何这样做是一个非常糟糕的主意!永远不要连接字符串来构建SQL命令。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。改为使用参数化查询。

如果你这样做,你的错误很有可能同时消失。
If that is the code that gives the error, then it likely that it's due to the content of your textbox or your combo: and doing it like that is a very bad idea anyway! Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
If you do that, there is a very good chance that your error will disappear at the same time.


这篇关于我的代码背后有错误请跟踪我的问题..... oledbexception是适合的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆