|
|
asp.net c# กด ตกลงเพื่อให้หาวันที่ ที่อยู่ระหว่าง textbox1 และ textbox2 มาแสดง error ดังภาพรบกวนช่วยเหลือด้วยครับ |
|
|
|
|
|
|
|
Code (C#)
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection objConn = new SqlConnection();
SqlCommand objCmd = new SqlCommand();
SqlDataAdapter dtAdapter = new SqlDataAdapter();
DataSet ds = new DataSet();
DataTable dt = null;
string strConnString = null;
string strSQL = null;
strConnString = "Data Source = WAKDATABASE; Initial Catalog = OT; Persist Security Info=True;user ID = sa; password=P@ssw0rd;";
//strSQL = "SELECT Empid, Name, Lastname, Section, SUM(Getmoney) AS Expr1 FROM Cometowork WHERE Date like '%"+ TextBox1.Text +"%' GROUP BY Empid, Name, Lastname, Section ORDER BY Section";
strSQL = @"SELECT Empid, Name, Lastname, Section, SUM(Getmoney) AS Expr1 FROM Cometowork WHERE Date between
" + Convert.ToDateTime(TextBox1.Text).ToString("yyyy-MM-dd") + " and " + Convert.ToDateTime(TextBox2.Text).ToString("yyyy-MM-dd")
+ " GROUP BY Empid, Name, Lastname, Section ORDER BY Section";
objConn.ConnectionString = strConnString;
var _with1 = objCmd;
_with1.Connection = objConn;
_with1.CommandText = strSQL;
_with1.CommandType = CommandType.Text;
dtAdapter.SelectCommand = objCmd;
dtAdapter.Fill(ds);
dt = ds.Tables[0];
dtAdapter = null;
objConn.Close();
objConn = null;
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dt));
ReportViewer1.LocalReport.ReportPath = "ReportHR.rdlc";
ReportViewer1.LocalReport.Refresh();
}
Tag : C#, VS 2015 (.NET 4.x)
|
|
|
|
|
|
Date :
2019-03-13 09:08:13 |
By :
sakkapong |
View :
728 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2019-03-13 09:11:38 |
By :
sakkapong |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้ว ผมแก้ไขใช้แบบนี้ครับ
Code (C#)
protected void Button1_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
DataTable dt = null;
var date1 = DateTime.Parse(TextBox1.Text);
var date2 = DateTime.Parse(TextBox2.Text);
con.Open();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = @"SELECT Empid, Name, Lastname, Section, SUM(Getmoney) AS Expr1 FROM Cometowork WHERE Date between @textbox1 and @textbox2
group by Empid, Name, Lastname, Section order by Section";
cmd.Parameters.Add("@textbox1", SqlDbType.DateTime).Value = date1;
cmd.Parameters.Add("@textbox2", SqlDbType.DateTime).Value = date2;
dtAdapter.SelectCommand = cmd;
dtAdapter.Fill(ds);
dt = ds.Tables[0];
dtAdapter = null;
con.Close();
con = null;
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dt));
ReportViewer1.LocalReport.ReportPath = "ReportHR.rdlc";
ReportViewer1.LocalReport.Refresh();
}
|
|
|
|
|
Date :
2019-03-13 14:04:59 |
By :
sakkapong |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|