Query Problem or Code Wrong --- Need Support !
Hi guys !
I am trying to search my database with some value enterd by the user in a textbox.The search result has to be displayed in a ListBox on click of search button.
The problem is that when i use the LIKE predicate with 'A%' it gives all the values in ListBox but when i use LIKE predicate as LIKE '"+TextBox1.Text+"' the result is not shown and i get an error saying one or more Parameters are not given values.
PLease Please PLease Help me guys !
My code snippet is as follows:
void Search_Click(object Source, EventArgs e)
{
if (RadioButtonList1.SelectedIndex == 0)
{
// ....Intializing the Strings....//
tring connectionstring;
string queryString;
DataSet ds = new DataSet();
OleDbConnection dbconnection;
OleDbDataAdapter ad;
connectionstring = "Provider=Microsoft.Jet.OLeDb.4.0;DATA SOURCE=" +
Server.MapPath("\\Database\\New_Tool.mdb") ;
queryString = "SELECT Company_Name FROM CompanyName WHERE Company_Name LIKE '"TextBox1.Text"' ";
dbconnection = new OleDbConnection(connectionstring);
dbconnection.Open();
ad = new OleDbDataAdapter(queryString, dbconnection);
ad.Fill(ds,"Company_Name");
ListBox1.DataSource = ds;
ListBox1.DataTextField = "Company_Name";
ListBox1.DataValueField = "Company_Name";
ListBox1.DataBind();
}
}
Vinay Chugh
If I rest, I will rust ! Let's share the knowledge !
|