G
Guest
I am trying to get the number of records selected using the ExecuteNonQuery
(MARKED BELOW BY ***). It does not crash but returns a "-1". The select
returns one record. What am I doing wrong? please help.
strSQL = "SELECT [med-id], [animal-id], [animal-name], medication, date,
dosage, frequency, [vet-id], [veterinarian-name], notes FROM [medication]
WHERE [animal-id] = " + anum1;
cmSQL = new SqlCommand(strSQL, cnKennel);
if (cnKennel.State != ConnectionState.Open)
cnKennel.Open();
*** intRowsAffected = cmSQL.ExecuteNonQuery(); ***
drSQL = cmSQL.ExecuteReader();
if(drSQL.Read())
{
txtMedID.Text = drSQL["med-id"].ToString();
txtAnimalID.Text = drSQL["animal-id"].ToString();
txtAnimalName.Text = drSQL["animal-name"].ToString();
txtMedication.Text = drSQL["medication"].ToString();
txtDate.Text = drSQL["date"].ToString();
txtDosage.Text = drSQL["dosage"].ToString();
txtFreq.Text = drSQL["frequency"].ToString();
txtVetID.Text = drSQL["vet-id"].ToString();
gbVetName.Text = drSQL["veterinarian-name"].ToString();
txtMedNotes.Text = drSQL["notes"].ToString();
}
(MARKED BELOW BY ***). It does not crash but returns a "-1". The select
returns one record. What am I doing wrong? please help.
strSQL = "SELECT [med-id], [animal-id], [animal-name], medication, date,
dosage, frequency, [vet-id], [veterinarian-name], notes FROM [medication]
WHERE [animal-id] = " + anum1;
cmSQL = new SqlCommand(strSQL, cnKennel);
if (cnKennel.State != ConnectionState.Open)
cnKennel.Open();
*** intRowsAffected = cmSQL.ExecuteNonQuery(); ***
drSQL = cmSQL.ExecuteReader();
if(drSQL.Read())
{
txtMedID.Text = drSQL["med-id"].ToString();
txtAnimalID.Text = drSQL["animal-id"].ToString();
txtAnimalName.Text = drSQL["animal-name"].ToString();
txtMedication.Text = drSQL["medication"].ToString();
txtDate.Text = drSQL["date"].ToString();
txtDosage.Text = drSQL["dosage"].ToString();
txtFreq.Text = drSQL["frequency"].ToString();
txtVetID.Text = drSQL["vet-id"].ToString();
gbVetName.Text = drSQL["veterinarian-name"].ToString();
txtMedNotes.Text = drSQL["notes"].ToString();
}