Try using
sqldataadapter[
^]
SqlCommand cmd = new SqlCommand("select Antibiotic,RectionA,RectionB from Culture", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++)
{
if (i < 5) {
DataRow row = dt.Rows[i];
dataGridView5.Rows.Add(row["Antibiotic"].ToString(), row["RectionA"].ToString(), row["RectionB"].ToString());
}
}
This will display only the top 5 rows as per your code logic, if you want to load all the data to gridview, remove the
IF
condition