Israel

Israel

  • 952
  • 1.2k
  • 138.1k

Display ONLY the first record of datagrid from textbox on cl

Jan 18 2020 6:05 PM
Hi,
I wrote these codes to display the LAST row ONLY. Then how can I display ONLY the first row from textbox one click.
private void button_Click(object sender, EventArgs e)
{
string commandString = "select top 1 * from Test where name='" + txtNumber.Text ";
OleDbCommand sqlCmd = new OleDbCommand(commandString, sqlCon);
OleDbDataReader read = sqlCmd.ExecuteReader();
if (read.HasRows)
{
while (read.Read())
{
txtNumber.Text = read["number"].ToString();
}
}
else
{
MessageBox.Show("Name " + txtName.Text + " not found");
}
read.Close();
sqlCon.Close();

Answers (1)