0
Answer

How to AutoFill 2nd TextBox according to 1st TextBox from DB

Ask a question
q w

q w

9y
865
1
lbouly overHow to AutoFill second TextBox according to first TextBox with the corresponding data in the DataBase
there's a datatable with 2 column, 1st one is studentname & 2nd column is StudentAverage.
First txtbx is autosuggest(studentname). How to make the second txtbx automaticaly fill according to 1st txtbx (2nd txtbx fill with the corresponding record of second column (studentsavrage)?
 i mean, when i write someone's name in the first txtbox, the second txtbx automatically fills & shows its corresponding data(avrage)
this is for the 1st txtbx; it shows StudentNames
private void txtbxName_TextChanged(object sender, EventArgs e)

{

AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection();

string StrCmd = "SELECT * FROM School";

string ConnStr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\School_Database.accdb";

OleDbConnection MyConn = new OleDbConnection(ConnStr);

MyConn.Open();

OleDbCommand Cmd = new OleDbCommand(StrCmd, MyConn);

OleDbDataReader ObjReader = Cmd.ExecuteReader();

if (ObjReader != null)

{

while (ObjReader.Read())
namesCollection
.Add(ObjReader["StudentName"].ToString());

}

else

{

MessageBox.Show("Data not found");

}

ObjReader.Close();

MyConn.Close();

txtbxName.AutoCompleteMode = AutoCompleteMode.Suggest;

txtbxName.AutoCompleteSource = AutoCompleteSource.CustomSource; txtbxName.AutoCompleteCustomSource = namesCollection;

}