|
|
|
ต้องการค้นหาข้อมูลวันที่ะหว่าง textbox1 และ textbox2 แล้วนำมาแสดง report แต่ 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), Windows
|
|
|
|
|
|
Date :
2019-03-13 09:34:13 |
By :
sakkapong |
View :
750 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|