Im trying to write some simple code that will allow me to search an access database by the primary key and display the record. For the life of me I can't work out why every time I run the code and do a search it says that the record cannot be found, even though I know I'm searching an existing customer number (primary key).
I have very limited knowledge of programming so any help would be great.
The code I have is:
Code:protected void searchClicked(object sender, EventArgs e) { OleDbConnection con = null; OleDbCommand myCommand = null; OleDbDataReader myReader=null; string connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("amazonia280.mdb")+";"; if (SCust_No.Text.Length>0) { con=new OleDbConnection(connectionString); try { con.Open(); } catch (Exception exc) { Console.WriteLine("Problem opening connection"); } myCommand = new OleDbCommand("Select Cust_No, Cust_Name, Address, email, telno From Customer where Cust_No like '%<SCust_No.Text>%'", con); myReader = myCommand.ExecuteReader(); if (myReader.Read()) { Cust_No.Text = myReader.GetString(0); Cust_Name.Text = myReader.GetString(1); Address.Text = myReader.GetString(2); email.Text = myReader.GetString(3); telno.Text = myReader.GetString(4); myReader.Close(); con.Close(); SCust_NoError.Text=""; enableSearch(false); } else { myReader.Close(); con.Close(); SCust_NoError.Text="Customer Number not Found!!"; } } }



1Likes
LinkBack URL
About LinkBacks


