Hi I am trying to read data from database then put this into a table. rows in the table are created automatically depending on how many rows there are in database. I have done this in php using mysql_fetch_array but cannot seem to do it in asp.net webforms. My idea is to use this query to get the information and store in the labels in the server page and create a table there with coloumns data filled using the labels. Here is my code in the 'page_load' Thank you:
<table>
<tr>
<th>Surgery</th>
<th>PatientID</th>
<th>Location</th>
</tr>
<tr>
<td>
<asp:Label ID="Label1" runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="Label2" runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="Label3" runat="server"></asp:Label>
</td>
</tr>
</table>
string query= "select surgery,patientID, location from details";
SqlCommand result= new SqlCommand(query, conn);
result.ExecuteNonQuery();
using (SqlDataReader getInfo= result.ExecuteReader())
while (getInfo.Read())
{
Label1.Text = getInfo["surgery"].ToString();
Label2.Text = getInfo["patientID"].ToString();
Label3.Text = getInfo["location"].ToString();
}
SqlCommand cmd = new SqlCommand("select surgery, PatientID, location from details", conn); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); conn.Close();
GridView
. Possible duplicate of ASP.NET local SQL Server database C# gridview data binding Visual Studio 2013 – ShaharyarSystem.Data
in your project. – Shaharyar