protected void SearchBT_Click(object sender, EventArgs e) { decimal d1 = 0, d2 = 0; if (!string.IsNullOrEmpty(StyleTB.Text.Trim())) { 入庫應付LB.BackColor = System.Drawing.Color.White; 入庫應付LB.ForeColor = System.Drawing.Color.Black; 入庫暫估LB.BackColor = System.Drawing.Color.White; 入庫暫估LB.ForeColor = System.Drawing.Color.Black; DataTable dt = new DataTable(); using (SqlConnection Conn = new SqlConnection(strConnectString)) { SqlDataAdapter myAdapter = new SqlDataAdapter(DB1(), Conn); myAdapter.Fill(dt); //---- 這時候執行SQL指令。取出資料,放進 DataSet。 } if (dt.Rows.Count > 0) { d1 = Convert.ToDecimal(dt.Compute("Sum(數量)", "true")); GV1.DataSource = dt; GV1.DataBind(); } DataTable dt2 = new DataTable(); using (SqlConnection Conn = new SqlConnection(strConnectString)) { SqlDataAdapter myAdapter = new SqlDataAdapter(DB2(), Conn); myAdapter.Fill(dt2); //---- 這時候執行SQL指令。取出資料,放進 DataSet。 } if (dt2.Rows.Count > 0) { d2 = Convert.ToDecimal(dt2.Compute("Sum(數量)", "true")); GV2.DataSource = dt2; GV2.DataBind(); } 入庫應付LB.Text = d1.ToString(); 入庫暫估LB.Text = d2.ToString(); if (d1 > d2) { 入庫應付LB.BackColor = System.Drawing.Color.Red; 入庫應付LB.ForeColor = System.Drawing.Color.Yellow; } else if (d1 < d2) { 入庫暫估LB.BackColor = System.Drawing.Color.Red; 入庫暫估LB.ForeColor = System.Drawing.Color.Yellow; } } }
protected void Page_Load(object sender, EventArgs e) { //creating a table manually DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("BlogID", Type.GetType("System.String"))); dt.Columns.Add(new DataColumn("BlogText", Type.GetType("System.String"))); dt.Columns.Add(new DataColumn("Mood", Type.GetType("System.String"))); dt.Rows.Add(dt.NewRow()); dt.Rows.Add(dt.NewRow()); dt.Rows.Add(dt.NewRow()); dt.Rows[0]["BlogID"] = "FirstID"; dt.Rows[0]["BlogText"] = "Awesome!"; dt.Rows[0]["Mood"] = "This is for awesome people"; dt.Rows[1]["BlogID"] = "SecondID"; dt.Rows[1]["BlogText"] = "Take it easy..."; dt.Rows[1]["Mood"] = "Stop messing"; dt.Rows[2]["BlogID"] = "ThirdID"; dt.Rows[2]["BlogText"] = "Great!"; dt.Rows[2]["Mood"] = "Well done"; dt.PrimaryKey = new DataColumn[] { dt.Columns["BlogID"] }; GV3.DataSource = dt; GV3.DataBind(); DataSet ds = new DataSet(); ds.Tables.Add(dt); GV4.DataSource = ds.Tables[0]; GV4.DataBind(); DALBlog blogDAL = new DALBlog("cheeseConnectionString"); GV1.DataSource = blogDAL.GetDataTable("SELECT * FROM Blogs", "Blog"); GV1.DataBind(); Database db = DatabaseFactory.CreateDatabase("cheeseConnectionString"); GV2.DataSource = db.ExecuteDataSet(db.GetSqlStringCommand("SELECT * FROM Blogs")); GV2.DataBind(); }
protected void ShowNoti(object sender, EventArgs e) { String connectionString; SqlConnection cnn; connectionString = WebConfigurationManager.ConnectionStrings["constr"].ConnectionString; cnn = new SqlConnection(connectionString); cnn.Open(); //String ID = Id.Text; SqlCommand dbo = new SqlCommand("Show_Notification", cnn); dbo.CommandType = System.Data.CommandType.StoredProcedure; dbo.Parameters.Add(new SqlParameter("@user_id", Session["ids"])); GV2.DataSource = dbo.ExecuteReader(); GV2.DataBind(); }