Create this procedure to return the specified row:
Create Procedure GetFullName
@Name nVarchar(50)
As
Select FirstName,
LastName
From Table_Name
Where FirstName = @Name Or LastName = @Name
then execute that, and if there was a row so you can check if the user, entered firstName so textBox2.Text will be lastName and also the reverse is possible.
string firstName = string.Empty, lastName = string.Empty;
SqlConnection connection = new SqlConnection("write connectionString here");
SqlCommand command = new SqlCommand(connection);
command.Text = "GetFullName";
command.CommandType = CommandType.StoreProcedure;
try
{
command.Connection.Open();
SqlDataReader reader = command.ExecuteReader();
if (reader.Read())
{
firstName = (string)reader["FirstName"];
lastName = (string)reader["LastName"];
}
else
MessageBox.Show("No match found");
reader.Close();
}
catch { }
finally
{
if (command.Connection.State == ConnectionState.Open)
command.Connection.Close();
}
textBox2.Text == textBox1.Text == firstName ? lastName : firstName;