Error:
An unhandled exception of type
System.IndexOutOfRangeException
occurred inSystem.Data.dll
Additional information: There is no row at position 1.
Code:
private void Form11_Load(object sender, EventArgs e) {
SqlConnection con = new SqlConnection(@"Data Source=(localdb)\ProjectsV12;Initial Catalog=Hospital;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;");
SqlDataAdapter sda = new SqlDataAdapter("SELECT Name FROM Patient where Patient_ID = '" + textBox1.Text + "';", con);
DataTable dt = new DataTable();
sda.Fill(dt);
textBox2.Text = dt.Rows[1]["Name"].ToString();
}
Whenever I click the button for this page it shows the exception. I want to get the name this but it gives this unhandled exception every time.