0
我想在我的Asp.new c#表單中的網格視圖中顯示我的數據。 我正在使用Wamp Server的MySQL數據庫。 我已經厭倦了很多綁定數據庫的網格視圖。 請幫忙。Asp.net C#中的網格視圖wamp服務器的MYSQL
我的代碼:
public partial class Temp : System.Web.UI.Page
{
string conString = ConfigurationManager.ConnectionStrings["AASProject"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
MySqlConnection con = new MySqlConnection(conString);
con.Open();
gvFoodDetail.RowEditing+= new GridViewEditEventHandler(gvFoodDetail_RowEditing);
gvFoodDetail.RowDeleting += new GridViewDeleteEventHandler(gvFoodDetail_RowDeleting);
gvFoodDetail.RowUpdating += new GridViewUpdateEventHandler(gvFoodDetail_RowUpdating);
//gvFoodDetail_RowCancelingEdit += new GridViewCancelEditEventArgs(gv);
// gvFoodDetail.RowEditing += new GridViewEditEventHandler(gvFoodDetail_RowEditing);
// gvFoodDetail.RowDeleting += new GridViewDeleteEventHandler(gvFoodDetail_RowDeleting);
// gvFoodDetail.RowUpdating += new GridViewUpdateEventHandler(gvFoodDetail_RowUpdating);
// gvFoodDetail.RowCancelingEdit += new GridViewCancelEditEventHandler(gvFoodDetail_RowCancelingEdit);
gvFoodDetail.PageIndexChanging += new GridViewPageEventHandler(gvFoodDetail_PageIndexChanging);
if (!IsPostBack)
{
gvFoodDetail.Visible = true;
loadFoodDB();
}
}
public void loadFoodDB()
{
string getFoodDetails = "Select Emp_ID,intime,outtime,date From datetime";
MySqlConnection con = new MySqlConnection(conString);
con.Open();
MySqlCommand cmd = new MySqlCommand(getFoodDetails, con);
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
da.Fill(dt);
con.Close();
gvFoodDetail.DataSource = dt;
gvFoodDetail.DataBind();
}
我已經實現了沒有數據庫的網格視圖,它正在工作perfact.I也成功地連接了數據庫。 – misri 2012-04-09 12:51:48
你可以顯示你的代碼到目前爲止?爲了連接數據庫*和*爲'GridView'? – jadarnel27 2012-04-09 13:14:21
顯示一些代碼,我們將從那裏幫助您 – dansasu11 2012-04-09 13:33:05