嗨我想從數據庫中讀取數據,然後把它放到一個表中。根據數據庫中有多少行自動創建表中的行。我在php中使用mysql_fetch_array完成了這項工作,但似乎無法在asp.net webforms中完成。我的想法是使用此查詢來獲取信息並存儲在服務器頁面的標籤中,並使用標籤填充顏色數據創建一個表格。這裏是我的代碼在 'Page_Load中' 謝謝你,在asp.net中的mysql_fetch_array webforms
<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 =新的SqlCommand( 「選擇手術,PatientID,從細節位置」,conn);在 SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); conn.Close();
使用'GridView'。可能的重複[ASP.NET本地SQL Server數據庫C#gridview數據綁定Visual Studio 2013](http://stackoverflow.com/questions/26817272/asp-net-local-sql-server-database-c-sharp-gridview- data-binding-visual-studio-20) – Shaharyar
已經嘗試過,似乎沒有工作? –
這些要求可以通過GridView輕鬆實現,您是否嘗試過?如果是,請分享該代碼。 – Shaharyar