Hi
I am new to C# so please excuse how bad my code is but I have written code to return values based on a search box however at times, the
value entered into the search box can apply to several records within an MSAccess DB.
Is there a way where I can scroll through the records that apply to the value in the search box by using a button?
public void LoopThroughRecs(OleDbDataReader Data) { Data.Read(); { FirstName.Text = Data["Initial"].ToString(); LastName.Text = Data["Surname"].ToString(); Address1.Text = Data["Address 1"].ToString(); Address2.Text = Data["Address 2"].ToString(); Address3.Text = Data["Address 3"].ToString(); TownCity.Text = Data["Post Town"].ToString(); PostCode.Text = Data["Post Code"].ToString(); Telephone.Text = Data["Telephone"].ToString(); LstSvcDat.Text = Data["LastService"].ToString(); BoilerMan.Text = Data["Manufacturer"].ToString(); BoilerMod.Text = Data["Model"].ToString(); } Data.Close(); } public void button2_Click(object sender, EventArgs e) { System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(); conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=BoilerSvc_be.mdb"; try { conn.Open(); OleDbCommand command = new OleDbCommand("SELECT CustCode,Initial,Surname,[Address 1],[Address 2],[Address 3],[Post Town],[Post Code],Telephone,Equipment.CustID AS CustID,Equipment.Manufacturer AS Manufacturer,Equipment.Model AS Model,Equipment.LastService AS LastService FROM Contacts LEFT OUTER JOIN Equipment ON Equipment.CustID = Contacts.CustID WHERE Archived = 0 AND (CustCode = '" + textBox12.Text + "' OR Initial = '" + textBox12.Text + "' OR Surname = '" + textBox12.Text + "' OR Initial = '" + textBox12.Text + "' OR [Post Town] = '" + textBox12.Text + "' OR [Post Code] = '" + textBox12 + "')", conn); OleDbDataReader Data = command.ExecuteReader(); LoopThroughRecs(Data); } finally { conn.Close(); } }//Button 3 is to call next record
public void button3_Click_3(object sender, EventArgs e)
{
System.Data.OleDb.OleDbConnection conn = new
System.Data.OleDb.OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=BoilerSvc_be.mdb";
try
{
conn.Open();
OleDbCommand command = new OleDbCommand("SELECT CustCode,Initial,Surname,[Address 1],[Address 2],[Address 3],[Post Town],[Post Code],Telephone,Equipment.CustID AS CustID,Equipment.Manufacturer AS Manufacturer,Equipment.Model AS Model,Equipment.LastService AS LastService FROM Contacts LEFT OUTER JOIN Equipment ON Equipment.CustID = Contacts.CustID WHERE Archived = 0 AND(CustCode LIKE '" + textBox12.Text + "' OR Initial LIKE '" + textBox12.Text + "' OR Surname LIKE '" + textBox12.Text + "' OR Initial LIKE '" + textBox12.Text + "' OR [Post Town] LIKE '" + textBox12.Text + "' OR [Post Code] LIKE '" + textBox12 + "')", conn);
OleDbDataReader Reader = command.ExecuteReader();
LoopThroughRecs(Reader);
}
finally
{
conn.Close();
}
}