使用c#在Access DataBase中搜索记录的Proplem [英] Proplem with Search a record in Access DataBase using c#
本文介绍了使用c#在Access DataBase中搜索记录的Proplem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我通过ProductID寻找产品时,它的工作效果与Integer值一致,但是使用字符串Product Name,我遇到了问题。
when i was seeking a product by ProductID its working good with Integer value, but with string "Product Name", i am facing a problem.
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\WStoreSystem\\WStoreSystem\\WStoreSystem\\bin\\Debug\\StoreSys.mdb");
OleDbDataAdapter ad = new OleDbDataAdapter("select * from ProductsData where ProName=@ProName", con);
ad.SelectCommand.Parameters.Add("@ProName", OleDbType.Integer);
ad.SelectCommand.Parameters["@ProName"].Value = txtProductName.Text;
DataSet ds = new DataSet();
ad.Fill(ds, "Prod");
DGV1.DataSource = ds.Tables["Prod"];
if (ds.Tables["Prod"].Rows.Count > 0)
{
MessageBox.Show("The Product you are searching for is listed down");
}
else
{
MessageBox.Show("Sorry the Product was not found!!");
}
推荐答案
问题在这里
Problem is here
ad.SelectCommand.Parameters.Add("@ProName", OleDbType.Integer);
您忘记更改参数的值类型。你传递的是字符串类型,但是提到它是整数。
试试这个
You have forgotten to change the type of value for the parameter. You are passing string type but mentioned to be integer.
Try this
ad.SelectCommand.Parameters.Add("@ProName", OleDbType.VarChar);
希望,它有助于:)
Hope, it helps :)
这篇关于使用c#在Access DataBase中搜索记录的Proplem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文