从访问数据库(c#asp.net)检索数据时出现问题 [英] problem with retrieving data from access database (c# asp.net)

查看:74
本文介绍了从访问数据库(c#asp.net)检索数据时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正努力在表(Table1)的列(AD)中搜索字符串,并将其显示在Gridview1中.
但是,尽管数据集(ds)获得了必需的行,但程序给出了错误:

I am tring to search a string in a column(AD) of a table(Table1) and display it in Gridview1.
However, although dataset(ds) got the required row, program gives error:

Input string was not in a correct format.

没有任何行号或任何我尝试更改选择命令的内容,但无法解决问题.
谁能帮我解决这个问题.


without any line number or anything I tried to change select command but I could not fix the problem.
Can anyone help me about this problem.


public void Search()
    {
        OleDbConnection conn = new OleDbConnection();
        conn.ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + Server.MapPath("~/App_Data\\Database1.mdb");
        conn.Open();

        string sorgu = "Select * from Table1 where AD Like '" + TextBox1.Text +"'";

        OleDbDataAdapter adap = new OleDbDataAdapter(sorgu, conn);

        DataSet ds = new DataSet();

        adap.Fill(ds, "Table1");

        GridView1.DataSource = ds;
        GridView1.DataBind();

        conn.Close();
    }

推荐答案

使用类似这样的查询

use query like this

select * from table1 where AD like '%"+ TextBox1.Text+"%'";



现在您会得到答案.

希望对您有用!

再见



now you get answer.

i hope this is useful to you!!

take care bye bye


这篇关于从访问数据库(c#asp.net)检索数据时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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