|
|
|
ค้นหาข้อมูลตามวันที่ไม่ได้ ใช้ C# กับ Microsoft Access 2007 ครับ |
|
|
|
|
|
|
|
ผมเขียนโปรแกรมรวบรวมค่าโทรศัพท์ในแต่ละเบอร์ ออกมาเป็นรายเดือนครับว่าแต่ละเดือนเบอร์นี้ใช้ค่าโทรศัพท์ไปเท่าใด โดยค้นหาออกมาตามปีที่ต้องการและใช้ DateTimePicker ข้อมูลรันออก แต่พอกดค้นหามันไม่แสดงอะไรเลย ผิดตรงไหนหรือเปล่าครับรบกวนดูให้หน่อยนะครับ
Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Telephone
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbConnection Conn;
OleDbCommand com;
// OleDbTransaction tr;
StringBuilder sb = new StringBuilder();
DataSet ds = new DataSet();
string strConn;
private void Form1_Load(object sender, EventArgs e)
{
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\CALLDATA.mdb";
Conn = new OleDbConnection();
{
if (Conn.State == ConnectionState.Open)
{
Conn.Close();
}
Conn.ConnectionString = strConn;
Conn.Open();
DateTime Today = DateTime.Today;
DtpStart.Value = Today.AddYears(-1);
DtpEnd.Value = Today.AddYears(0);
}
}
private void btnSearch_Click(object sender, EventArgs e)
{
showdata();
}
private void showdata()
{
DateTime dateBegin = DtpStart.Value;
DateTime dateFinish = DtpEnd.Value;
sb.Remove(0, sb.Length);
sb.Append("SELECT EXTENSION, ");
sb.Append("sum(iif(month(STARTDATE)=1,AUTHCHARGE,0)) as [JAN],");
sb.Append("sum(iif(month(STARTDATE)=2,AUTHCHARGE,0)) as [FEB],");
sb.Append("sum(iif(month(STARTDATE)=3,AUTHCHARGE,0)) as [MAR],");
sb.Append("sum(iif(month(STARTDATE)=4,AUTHCHARGE,0)) as [APR],");
sb.Append("sum(iif(month(STARTDATE)=5,AUTHCHARGE,0)) as [MAY],");
sb.Append("sum(iif(month(STARTDATE)=6,AUTHCHARGE,0)) as [JUN],");
sb.Append("sum(iif(month(STARTDATE)=7,AUTHCHARGE,0)) as [JUL],");
sb.Append("sum(iif(month(STARTDATE)=8,AUTHCHARGE,0)) as [AUG],");
sb.Append("sum(iif(month(STARTDATE)=9,AUTHCHARGE,0)) as [SEP],");
sb.Append("sum(iif(month(STARTDATE)=10,AUTHCHARGE,0)) as [OCT],");
sb.Append("sum(iif(month(STARTDATE)=11,AUTHCHARGE,0)) as [NOV],");
sb.Append("sum(iif(month(STARTDATE)=12,AUTHCHARGE,0)) as [DEC],");
sb.Append("sum(AUTHCHARGE) as TOTAL");
sb.Append(" FROM CopyCALLDATA ");
sb.Append (" WHERE STARTDATE BETWEEN #" + dateBegin + "# AND #" + dateFinish + "#");
sb.Append(" GROUP BY EXTENSION ");
string sqlCustomer = sb.ToString();
OleDbDataReader dr;
DataTable dt;
com = new OleDbCommand();
{
com.CommandType = CommandType.Text;
com.CommandText = sqlCustomer;
com.Connection = Conn;
dr = com.ExecuteReader();
if (dr.HasRows)
{
dt = new DataTable();
dt.Load(dr);
myDgv.DataSource = dt;
}
else
{
myDgv.DataSource = null;
}
}
dr.Close();
}
}
}
Tag : .NET, Ms Access, Win (Windows App), C#, VS 2008 (.NET 3.x)
|
|
|
|
|
|
Date :
2011-11-25 11:30:21 |
By :
super_skywalker |
View :
1162 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เขียน .NET ง่ายเลยครับ Debug ดู Error Message ครับ
|
|
|
|
|
Date :
2011-11-25 11:55:06 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|