codify
Member
- Joined
- Dec 4, 2020
- Messages
- 18
- Programming Experience
- 1-3
Hello! In a window form, Patient id is being stored in both text box1 and textbox2. It is not storing the name of the patient in textbox2. Please help!
C#:
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-A85V0ME\SQLEXPRESS;Initial Catalog=Hospitalmanagement;Integrated Security=True");
con.Open();
if (textBox1.Text != "")
{
try
{
string getCust = "select id,name,gen,age,date,cont,addr,disease,status,r_type,building,r_no,price from patient where id=" + Convert.ToInt32(textBox1.Text) + " ;";
SqlCommand cmd = new SqlCommand(getCust, con);
SqlDataReader dr;
dr = cmd.ExecuteReader();
if (dr.Read())
{
textBox2.Text = dr.GetValue(0).ToString();
if (dr[1].ToString() == "Male")
{
radioButton1.Checked = true;
}
else if (dr[1].ToString() == "Female")
{
radioButton2.Checked = true;
}
textBox3.Text = dr.GetValue(1).ToString();
textBox3.Text = dr.GetValue(3).ToString();
textBox4.Text = dr.GetValue(4).ToString();
textBox5.Text = dr.GetValue(5).ToString();
textBox6.Text = dr.GetValue(6).ToString();
textBox7.Text = dr.GetValue(7).ToString();
textBox8.Text = dr.GetValue(8).ToString();
textBox9.Text = dr.GetValue(10).ToString();
textBox10.Text = dr.GetValue(9).ToString();
textBox11.Text = dr.GetValue(11).ToString();
textBox12.Text = dr.GetValue(12).ToString();
}
else
{
MessageBox.Show(" Sorry, This ID, " + textBox1.Text + " Staff is not Available. ");
textBox1.Text = "";
}
}
catch (SqlException excep)
{
MessageBox.Show(excep.Message);
}
con.Close();
}
}