Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.


C#
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();
    }
Posted
Updated 24-Aug-11 2:44am
v2
Comments
Paul E Davies 24-Aug-11 8:53am    
Do you get a response when you wildcard the like statement, ie "Select * from table1 where ad like '*" +Textbox1.text+"*'" ?
elvantambura 24-Aug-11 8:58am    
No I did not get any response. it is still same error.

1 solution

use query like this

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


now you get answer.

i hope this is useful to you!!

take care bye bye
 
Share this answer
 
v2
Comments
elvantambura 24-Aug-11 8:56am    
Thanks for solution but I tried this before but nothing changes.
angappans 24-Aug-11 9:16am    
did you check your datafield in database that is may be change
Paul E Davies 24-Aug-11 8:56am    
it's a while since I've queried Access but IIRC it uses * instead of % but I may be wrong.
elvantambura 24-Aug-11 8:59am    
I tried it and no change again:(
Paul E Davies 24-Aug-11 9:02am    
Sorry read the post properly now - you can get the row with response from the DB query then it's not your select that is at fault but the assign of ds as your datasource. Can you post the content of the row?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900