public void bind() { DB db = new DB(); SqlConnection con = new SqlConnection(); con = db.GetCon(); string str = "select jobskyer.jobskyerID,jobskyer.jobName,myDutyTime.dutyInTime,myDutyTime.dutyOutTime,myDutyTime.flag0,myDutyTime.flag1 from jobskyer,myDutyTime where jobskyer.jobskyerID=myDutyTime.jobskyerID"; SqlCommand com = new SqlCommand(str, con); SqlDataAdapter da = new SqlDataAdapter(com); DataSet ds = new DataSet(); da.Fill(ds); int k = ds.Tables[0].Rows.Count; for (int i = 0; i < k; i++) { string tojobskyerID = ds.Tables[0].Rows[i]["toJobskyerID"].ToString(); string select = "SELECT jobName FROM JOBSKYER WHERE jobskyerID='" + tojobskyerID + "'"; DB db1 = new DB(); SqlConnection con1 = new SqlConnection(); con1 = db1.GetCon(); string str1 = "select jobName from jobskyer where jobskyerID='" + tojobskyerID + "'"; SqlCommand com1 = new SqlCommand(str1, con1); SqlDataAdapter da1 = new SqlDataAdapter(com1); DataSet ds1 = new DataSet(); da1.Fill(ds1); string jobname = ds1.Tables[0].Rows[0]["jobName"].ToString(); ds.Tables[0].Rows[i]["jobName"] = jobname; if (i == k) { com1.Dispose(); con1.Close(); } } try { DutyRecordGridView.DataSource = ds; DutyRecordGridView.DataKeyNames = new string[] { "jobskyerID" }; DutyRecordGridView.DataBind(); } catch (Exception ex) { Response.Write(ex.Message); } finally { com.Dispose(); con.Close(); } }
protected void FromExcel_Click(object sender, EventArgs e) { DutyRecordGridView.DataSource = CreateDataSource(); DutyRecordGridView.DataBind(); }