主题:關於數據庫查詢
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.ListBox ListBox1;
public connStr conStr=new connStr();
private void Page_Load(object sender, System.EventArgs e)
{
// 在這裡放置使用者程式碼以初始化網頁
string str = "select FirstName from BookAuthors";
DataTable dt = this.GetData(str);
this.ListBox1.DataSource = dt;
DataBind();
}
public string ImageURL
{
get
{
return "JericPeng";
}
}
public DataTable GetData(string strSql)
{
System.Data.SqlClient.SqlConnection conn =
new System.Data.SqlClient.SqlConnection(conStr.SQLConnectionString);
conn.Open();
System.Data.SqlClient.SqlDataAdapter ada= new System.Data.SqlClient.SqlDataAdapter(strSql,conn);
System.Data.DataSet ds = new DataSet();
ada.Fill(ds);
conn.Close();
return ds.Tables[0];
}
請問我的ListBox1顯示的記錄全部是System.Data.DataRowView?
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.ListBox ListBox1;
public connStr conStr=new connStr();
private void Page_Load(object sender, System.EventArgs e)
{
// 在這裡放置使用者程式碼以初始化網頁
string str = "select FirstName from BookAuthors";
DataTable dt = this.GetData(str);
this.ListBox1.DataSource = dt;
DataBind();
}
public string ImageURL
{
get
{
return "JericPeng";
}
}
public DataTable GetData(string strSql)
{
System.Data.SqlClient.SqlConnection conn =
new System.Data.SqlClient.SqlConnection(conStr.SQLConnectionString);
conn.Open();
System.Data.SqlClient.SqlDataAdapter ada= new System.Data.SqlClient.SqlDataAdapter(strSql,conn);
System.Data.DataSet ds = new DataSet();
ada.Fill(ds);
conn.Close();
return ds.Tables[0];
}
請問我的ListBox1顯示的記錄全部是System.Data.DataRowView?