 |
|
search วันเดือนปี ไม่ขึ้นครับ รบกวนช่วยด้วยครับ ปวดหัวหลายวันแล้วครับ |
|
 |
|
|
 |
 |
|
ถ้าเป็น MS Access จะต้องใช้ #Date# AND #Date# ครับ
|
 |
 |
 |
 |
Date :
2014-10-28 09:14:33 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองปรับ format วันที่ของเครื่องคุณให้ตรงดูครับ
|
 |
 |
 |
 |
Date :
2014-10-28 09:36:51 |
By :
nongpaoza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ oledb command parameter
|
 |
 |
 |
 |
Date :
2014-10-28 10:22:00 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
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") + " and 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();
แบบนี้ไม่ครับ ผมรันแล้ว แต่ข้อมูลไม่ขึ้นครับ
|
 |
 |
 |
 |
Date :
2014-10-28 14:45:48 |
By :
ictm49 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
รวบกวนด้วยครับ เกือบเดือน อยู่กับค้นหาจากวันที่ครับ
|
 |
 |
 |
 |
Date :
2014-10-28 15:04:29 |
By :
ictm49 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
datepicker.value มัน return เป็น date อยู่แล้วจะแปลงเป็น string เพื่อ ????
|
 |
 |
 |
 |
Date :
2014-10-28 15:09:53 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขึ้น Error ครับ ขึ้นว่า Data type mismatch in criteria expression. ครับ
|
 |
 |
 |
 |
Date :
2014-10-28 16:08:44 |
By :
ictm49 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

ตาราง ใน database ครับ
|
 |
 |
 |
 |
Date :
2014-10-28 16:16:58 |
By :
ictm49 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
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();
|
 |
 |
 |
 |
Date :
2014-10-28 16:32:49 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Error ครับ หัวข้อที่ Error น่ะครับ
OleDbException was unhandled
ส่วนข้อความครับ
Data type mismatch in criteria expression.
รูปครับ ใน visual studio ครับ

|
 |
 |
 |
 |
Date :
2014-10-28 16:53:37 |
By :
ictm49 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
OleDbCommand command = new OleDbCommand("select Date_begin from Borlist where Date_begin>='2014-10-11' ", connection);
ลองเขียนเข้าไปตรงๆ ว่าทำงานได้ไหม
ถ้าทำงานได้ ไปดูข้อกำหนด ของ datepicker อีกทีครับ ว่า result ของมันควรเป็นในรูปแบบใด
|
 |
 |
 |
 |
Date :
2014-10-28 17:07:49 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอดูหน้า access ที่เป็นวันที่ตอนเปิดตารางหน่อยได้ไม๊ครับอยากรู้ว่าใช้ format อะไร
|
 |
 |
 |
 |
Date :
2014-10-28 17:10:40 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังไม่ได้เลยครับ
รูปน่ะครับ


|
 |
 |
 |
 |
Date :
2014-10-29 16:41:51 |
By :
ictm49 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง Upload ไฟล์ Project มาให้พี่ ๆ เขาช่วยไหมครับ ^^
|
 |
 |
 |
 |
Date :
2014-10-30 12:54:41 |
By :
fonfire |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แหะ ๆ แบบว่า เห็นช่วยกันเยอะแล้ว แต่ยังแก้ไม่ได้
|
 |
 |
 |
 |
Date :
2014-10-30 13:34:07 |
By :
fonfire |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังไม่ได้เลยครับ
พอใส่ "+dateTimePicker.value+" หรือ "dateTimePicker.value.Tostring("dd/MM/yyyy")";
ค้นหาได้ แต่ข้อมูลไม่ขึ้น
ส่วนพอใส่
'"+dateTimePicker.value+"' หรือ '"+dateTimePicker.value.Tostring("dd/MM/yyyy")"';
Error น่ะครับ ขึ้นว่า Data type mismatch in criteria expression. ครับ
|
 |
 |
 |
 |
Date :
2014-10-30 14:37:11 |
By :
ictm49 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
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;
|
 |
 |
 |
 |
Date :
2014-10-30 15:54:38 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เห็นท่าน No. 21 ให้ใช้แบบ แก้การ query เป็นแบบ parameter
ส่วนตัวผมไม่เก่งด้าน query ครั้นจะไปทำตัวขั้นเทพเหมือนคนอื่นก็กระไรยุ
ผมใช้วิธี add data souces แล้วตรวจผ่าน dataadabter ของ table นั้นๆดูเราจะได้ syntex ที่เราต้องการแบบไม่ต้องเดายากเลยครับ
ลองทำดู

|
 |
 |
 |
 |
Date :
2014-10-30 16:20:27 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
public static System.Data.DataTable GetTableForm(string strConn,DateTime dtStart,DateTime dtFinal)
{
System.Data.DataSet ds = new System.Data.DataSet();
string _SQL "WHERE Date_begin BETWEEN '" + dtStart + "' AND '" + dtFinal + "'" ;
System.Data.OleDb.OleDbConnection conn2 = new System.Data.OleDb.OleDbConnection(strConn);
conn2.Open();
System.Data.OleDb.OleDbDataAdapter adapter2 = new System.Data.OleDb.OleDbDataAdapter(_SQL, conn2);
return ds.Tables[0];
}
ว่าจะไม่ขายโง่นะเนี๊ย โค๊ดแบบบ้านๆของผมครับลองดู
ถ้าอยากแชร์ ก็มีเยอะครับ เว็บแชร์ gmail 4shared one2up(ของชอบ อิอิ)
|
 |
 |
 |
 |
Date :
2014-10-30 17:12:30 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
http://stackoverflow.com/questions/10473237/search-value-between-2-datetime-in-c-sharp
https://www.thaicreate.com/dotnet/forum/071381.html
เอาใจช่วยครับ
|
 |
 |
 |
 |
Date :
2014-10-30 17:22:00 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เกียวไม่ครับ กับตอนที่เรา insert เข้าฐานข้อมูล ทำยังไงข้อมูลไม่ยอมขึ้นเลยครับ
|
 |
 |
 |
 |
Date :
2014-10-30 17:57:44 |
By :
ictm49 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่มีเงื่อนไขก็ไม่ออกเหรอ
|
 |
 |
 |
 |
Date :
2014-10-30 18:02:07 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังไม่ได้อีกเรอะครับโค๊ดบ้านๆผมได้ป่าวครับ
|
 |
 |
 |
 |
Date :
2014-10-30 18:15:17 |
By :
lamaka.tor |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอบความคิดเห็นที่ : 33 เขียนโดย : lamaka.tor เมื่อวันที่ 2014-10-30 18:15:17
รายละเอียดของการตอบ ::
อย่ามั่วดิ
วิเคราะห์ดีๆ มันไม่ได้เงื่อนกับโค้ดนะเฟ้ย
เห็นว่าเอาเงื่อนไขออก ก็เรียกข้อมูลมาได้แล้ว
แสดงว่าเป็นที่เงื่อนไข
ทีนี้ต้องมีคิดต่อว่าทำไมเงื่อนไขไม่ตรง
ในใจเราคิดว่า อาจจะเพราะ พ.ศ. ค.ศ. หรือเปล่า
ปกติใน database จะเก็บเป็น ค.ศ.
แต่ถ้าเกิด insert ค.ศ. 2557 (เพราะคิดว่า + 543 แล้วจะเท่ากับ พ.ศ.)
เวลาเรียกด้วย พ.ศ. 2557 (ค.ศ. 2014) ก็คงไม่ออก
จำไว้กฏอีกข้อมูลของการใช้ datetime ก็ใช้ ค.ศ. เท่านั้น
อยากได้ พ.ศ. ให้แปลง cultrue ตอนแสดงผลก็พอ
|
 |
 |
 |
 |
Date :
2014-10-30 19:07:39 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อยากให้ลองแปลง ค่า เป็น unixtime เอาออกมาดูครับว่า มันเท่าไหร่
ผมให้ลองเรียกเข้าไปตรงๆ ตั้งแต่ คห. 15 datetime='2014-10-27' รูปแบบนี้ ได้ลองมั้งหรือยังครับ
ถ้าลองแล้วไม่ออก ก็ว่าจะให้ลอง '2557-10-27' อีกครั้ง ถ้าออก
ก็สรุปได้ว่า คีย์ปี คศ 2557 ก็ให้ลบ 543 ออก ก็จะได้ ข้อมูลเป็นจริง
โปรแกรมเมอร์ ไม่มีใครเก่งตลอดเวลาหรอกครับ มีบางครั้งที่สภาพร่างกายและจิดใจไม่พร้อม ก็จะมองปัญหาไม่ออก
ก็ลองทำตาม ความคิดของคนอื่นดูบ้างนะครับ
อย่าง คุณ "ห้ามตอบเกินวันละ 2 กระทู้" น่าจะลองทำตาม ดูบ้างนะครับ
แม้บ้างครั้งแกจะตอบแบบไม่ได้คำตอบตรงๆ ก็ตามทีแต่ก็ได้ประโยชน์อยู่นะครับ
|
 |
 |
 |
 |
Date :
2014-10-30 19:36:48 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับ ขอบคุณมากทุกกระทู้น่ะครับ ขอบคุณมากจริงๆที่ให้ความช่วยเหลือ
|
 |
 |
 |
 |
Date :
2014-10-30 20:54:26 |
By :
ictm49 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ่อครับ
ลืม....
แต่ไม่รู้ปัญหาจริงๆครับ
โค้ดที่เขียนได้ครับCode (C#)
DataTable dt = new DataTable();
connection.Open();
using (OleDbCommand command = connection.CreateCommand())
{
StringBuilder commandString = new StringBuilder();
commandString.AppendLine("SELECT bl.Borrow_id,bl.Date_begin,bc.Id_card,c.Sname,c.Tel,t.Type_name,t.Percen,t.Type,bc.Weight,r.Duration,r.Rate,bl.Babout_cost,r.R_ID,bl.Date_receive,r.Date");
commandString.AppendLine("FROM Borcus bc,Borlist bl,Custumer c,Type t,Rate r");
commandString.AppendLine("WHERE bc.Borrow_id=bl.Borrow_id and bc.Id_card=c.Id_card and bc.Type_id=t.Type_id and bl.R_ID=r.R_ID and bl.P_no='01' AND Date_begin BETWEEN @Start AND @End;");
//command.CommandTimeout = 30;
command.CommandType = CommandType.Text;
command.CommandText = commandString.ToString();
command.Parameters.AddWithValue("@Start", this.dateTimePicker1.Value.ToShortDateString());
command.Parameters.AddWithValue("@End", this.dateTimePicker2.Value.ToShortDateString());
using (OleDbDataAdapter adapter = new OleDbDataAdapter())
{
adapter.SelectCommand = command;
adapter.Fill(dt);
}
this.dataGridView2.DataSource = dt;
dataGridView2.Columns["Duration"].Visible = false;
dataGridView2.Columns["Rate"].Visible = false;
dataGridView2.Columns["R_ID"].Visible = false;
dataGridView2.Columns["Date_receive"].Visible = false;
dataGridView2.Columns["Date"].Visible = false;
string[] header = { "เลขที่สัญญา", "วันที่ทำสัญญา", "เลขบัตร ปชช.", "ชื่อลูกค้า", "เบอร์โทรศัพท์", "ชนิดสินค้า", "เปอร์เซ็นต์ %", "ประเภท", "น้ำหนัก" };
for (int i = 0; i < header.Length; i++)
{
dataGridView2.Columns[i].HeaderText = header[i];
}
}
connection.Close();
|
 |
 |
 |
 |
Date :
2014-11-02 08:37:20 |
By :
ictm49 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูครับครับ บ้านๆๆเลย
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 คือ เดือน กะ วันตามลำดับ
strSQL = ""
strSQL = strSQL & " select "
strSQL = strSQL & " costomer.name"
strSQL = strSQL & " ,costomer.id_card"
strSQL = strSQL & " ,costomer.address"
strSQL = strSQL & " ,costomer.tel"
strSQL = strSQL & " ,count(booking.booking_code) as booking_code"
strSQL = strSQL & " from booking"
strSQL = strSQL & " inner join costomer "
strSQL = strSQL & " on booking.id_card = costomer.id_card"
strSQL = strSQL & " where right(booking.CheckIn,4)+mid(booking.CheckIn,4,2)+left(booking.CheckIn,2) >= '" + fromdate + "'"
strSQL = strSQL & " and right(booking.CheckIn,4)+mid(booking.CheckIn,4,2)+left(booking.CheckIn,2) <= '" + todate + "'"
strSQL = strSQL & " and costomer.code like '%" & Me.txtcustomer_code.Text & "%' and costomer.name like '%" & Me.txtcustomer_name.Text & "%'"
strSQL = strSQL & " group by"
strSQL = strSQL & " costomer.name"
strSQL = strSQL & " ,costomer.id_card"
strSQL = strSQL & " ,costomer.address"
strSQL = strSQL & " ,costomer.tel"
dtAdapter = New OleDbDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
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
Param1Field.ParameterFieldName = "PrintBy"
Param1Value.Value = USER.EMPLOYEENAME
Param1Field.CurrentValues.Add(Param1Value)
ParamFields.Add(Param1Field)
Param2Field.ParameterFieldName = "PrintDateTime"
Param2Value.Value = DateTime.Now.ToString("d MMMM yyyy")
Param2Field.CurrentValues.Add(Param2Value)
ParamFields.Add(Param2Field)
Param4Field.ParameterFieldName = "docdateform"
Param4Value.Value = Me.dtpdocdatefrom.Value
Param4Field.CurrentValues.Add(Param4Value)
ParamFields.Add(Param4Field)
Param5Field.ParameterFieldName = "docdateto"
Param5Value.Value = Me.dtpdocdateto.Value
Param5Field.CurrentValues.Add(Param5Value)
ParamFields.Add(Param5Field)
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
ฝากกลุ่มด้วยครับ https://www.facebook.com/groups/721774164538048/
|
 |
 |
 |
 |
Date :
2014-11-02 16:38:29 |
By :
เบนโตะ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|