ToString("dd/MM/yyyy hh:mm:ss") ต้องให้สอดคล้องกะ format ที่ตั้งไว้ครับ
ต้องไปดู format
1. ลองใช้แค่ dateTimePicker1.Value ดู
2. ดูทีละข้างครับอย่าเพิ่งใช้ And
Code (C#)
connection.Open();
OleDbCommand command = new OleDbCommand("select Date_begin from Borlist where Date_begin>='" + dateTimePicker1.Value.ToString("dd/MM/yyyy hh:mm:ss") + "'", connection);
//command.ExecuteNonQuery();
DataTable dt1 = new DataTable();
OleDbDataAdapter da1 = new OleDbDataAdapter(command);
da1.Fill(dt1);
dataGridView2.DataSource = dt1;
connection.Close();
และ
Code (C#)
connection.Open();
OleDbCommand command = new OleDbCommand("select Date_begin from Borlist where Date_begin <='" + dateTimePicker2.Value.ToString("dd/MM/yyyy hh:mm:ss") + "'", connection);
//command.ExecuteNonQuery();
DataTable dt1 = new DataTable();
OleDbDataAdapter da1 = new OleDbDataAdapter(command);
da1.Fill(dt1);
dataGridView2.DataSource = dt1;
connection.Close();
ส่วนพอใส่
'"+dateTimePicker.value+"' หรือ '"+dateTimePicker.value.Tostring("dd/MM/yyyy")"';
Error น่ะครับ ขึ้นว่า Data type mismatch in criteria expression. ครับ
Date :
2014-10-30 14:37:11
By :
ictm49
No. 24
Guest
Code (C#)
DataTable dt = new DataTable();
string connectionString = "up to you";
using (OleDbConection connection = new OleDbConection(connectionString))
using (OleDbCommand command = connection.CreateCommand())
{
StringBuilder commandString = new StringBuilder();
commandString.AppendLine("SELECT Date_begin");
commandString.AppendLine("FROM Borlist");
commandString.AppendLine("WHERE Date_begin BETWEEN @Start AND @End;");
command.CommandTimeout = 30;
command.CommandType = CommandType.Text;
command.CommandText = commandString.ToString();
command.Parameters.AddWithValue("@Start", this.dateTimePicker1.Value.Date);
command.Parameters.AddWithValue("@End", this.dateTimePicker2.Value.Date);
using (OleDbDataAdapter adapter = new OleDbDataAdapter())
{
adapter.SelectCommand = command;
adapter.Fill(dt);
}
}
this.dataGridView2.DataSource = dt;
Public Function ToolbarPrint() As ToolbarFoundation.Answer Implements ToolbarFoundation.IToolbarFoundation.ToolbarPrint
objConn = New OleDbConnection(connectString)
objConn.Open()
dt = New DataTable
Dim strSQL As String
Dim day2 As Date = Me.dtpdocdatefrom.Value
Dim day3 As Date = Me.dtpdocdateto.Value
Dim str1() As String
Dim str2() As String
Dim fromdate As String = ""
Dim todate As String = ""
Dim c1() As Char = {"/"c}
Dim c11() As Char = {"/"c}
Dim a As String = day2.ToShortDateString
Dim b As String = day3.ToShortDateString
str1 = a.Split(c1, StringSplitOptions.None)
str2 = b.Split(c11, StringSplitOptions.None)
fromdate = str1(2) + str1(1) + str1(0)
todate = str2(2) + str2(1) + str2(0)
'-----------> 2 คือ พ.ศ. 1,0 คือ เดือน กะ วันตามลำดับ
If dt.Rows.Count > 0 Then
'<Parameter>
Dim ParamFields As New CrystalDecisions.Shared.ParameterFields
Dim Param1Field As New CrystalDecisions.Shared.ParameterField
Dim Param1Value As New CrystalDecisions.Shared.ParameterDiscreteValue
Dim Param2Field As New CrystalDecisions.Shared.ParameterField
Dim Param2Value As New CrystalDecisions.Shared.ParameterDiscreteValue
Dim Param3Field As New CrystalDecisions.Shared.ParameterField
Dim Param3Value As New CrystalDecisions.Shared.ParameterDiscreteValue
Dim Param4Field As New CrystalDecisions.Shared.ParameterField
Dim Param4Value As New CrystalDecisions.Shared.ParameterDiscreteValue
Dim Param5Field As New CrystalDecisions.Shared.ParameterField
Dim Param5Value As New CrystalDecisions.Shared.ParameterDiscreteValue
Dim Rpt As New Rpthistory
Dim objReport As New FrmPrintPreview
objReport.ParameterFields = ParamFields
objReport.DT = dt
objReport.Report = Rpt
objReport.ShowDialog()
Else
MessageBox.Show("ไม่พบข้อมูลที่ค้นหา", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Function