嗨Stackoverflow管理員和所有成員,我有問題,當我按日期動態列datagridview。動態日期之間的日期範圍在mysql vb.net
我有一些表酒店預訂:
CREATE TABLE IF NOT EXISTS `tp_tblmsroom` (
`KdRoom` varchar(10) COLLATE latin1_general_ci NOT NULL DEFAULT '',
`NmRoom` varchar(100) COLLATE latin1_general_ci NOT NULL,
`KdRoomType` varchar(10) COLLATE latin1_general_ci NOT NULL
PRIMARY KEY (`KdRoom`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
INSERT INTO `tp_tblmsroom` (`KdRoom`, `NmRoom`, `KdRoomType`) VALUES
('1001', 'Lantai 1 No. 001', 'SNG-SUP'),
('1002', 'Lantai 1 No. 002', 'SNG-SUP'),
('2001', 'Lantai 2 No. 001', 'SNG-DLX'),
('2002', 'Lantai 2 No. 002', 'SNG-DLX'),
('3001', 'Lantai 3 No. 001', 'TWN-JRS'),
('3002', 'Lantai 3 No. 002', 'TWN-JRS'),
('3003', 'Lantai 3 No. 003', 'TWN-JRS'),
('4001', 'Lantai 4 No. 001', 'SNG-STE'),
('5001', 'Lantai 5 No. 001', 'TWN-PRE'),
('6001', 'Lantai 6 No. 001', 'SNG-STD'),
('6002', 'Lantai 6 No. 002', 'SNG-STD'),
('6003', 'Lantai 6 No. 003', 'SNG-STD'),
('6004', 'Lantai 6 No. 004', 'SNG-STD'),
('6005', 'Lantai 6 No. 005', 'SNG-STD'),
('6006', 'Lantai 6 No. 006', 'TWN-STD'),
('6007', 'Lantai 6 No. 007', 'TWN-STD'),
('6008', 'Lantai 6 No. 008', 'TWN-STD'),
('6009', 'Lantai 6 No. 009', 'TWN-STD');
CREATE TABLE IF NOT EXISTS `tp_tblstroomstatus` (
`KdRoom` varchar(10) COLLATE latin1_general_ci NOT NULL,
`DateCheck` datetime NOT NULL,
`KdRoomStatus` varchar(10) COLLATE latin1_general_ci NOT NULL,
`KdTransaksi` varchar(21) COLLATE latin1_general_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
INSERT INTO `tp_tblstroomstatus` (`KdRoom`, `DateCheck`, `KdRoomStatus`) VALUES
('6006', '2016-11-22 14:00:00', 'BO'),
('6006', '2016-11-23 14:00:00', 'BO'),
('6006', '2016-11-23 12:00:00', 'BO'),
('6006', '2016-11-24 12:00:00', 'BO'),
('6007', '2016-11-22 14:00:00', 'BO'),
('6007', '2016-11-23 14:00:00', 'BO'),
('6007', '2016-11-24 14:00:00', 'BO'),
('6007', '2016-11-23 12:00:00', 'BO'),
('6007', '2016-11-24 12:00:00', 'BO'),
('6007', '2016-11-25 12:00:00', 'BO');
我試圖創建一個查詢,以使日期的動態,當我在VB.NET 2的DateTimePicker和綁定之間打電話datagridview的。
SELECT `tp_tblmsroom`.`KdRoom`,
MAX(IF(`tp_tblstroomstatus`.`DateCheck` = '2016-11-20 14:00:00', `tp_tblstroomstatus`.`KdRoomStatus`, '')) AS `2016-11-20 14:00:00`,
MAX(IF(`tp_tblstroomstatus`.`DateCheck` = '2016-11-21 12:00:00', `tp_tblstroomstatus`.`KdRoomStatus`, '')) AS `2016-11-21 12:00:00`,
MAX(IF(`tp_tblstroomstatus`.`DateCheck` = '2016-11-21 14:00:00', `tp_tblstroomstatus`.`KdRoomStatus`, '')) AS `2016-11-21 14:00:00`,
MAX(IF(`tp_tblstroomstatus`.`DateCheck` = '2016-11-22 12:00:00', `tp_tblstroomstatus`.`KdRoomStatus`, '')) AS `2016-11-22 12:00:00`,
MAX(IF(`tp_tblstroomstatus`.`DateCheck` = '2016-11-22 14:00:00', `tp_tblstroomstatus`.`KdRoomStatus`, '')) AS `2016-11-22 14:00:00`,
MAX(IF(`tp_tblstroomstatus`.`DateCheck` = '2016-11-23 12:00:00', `tp_tblstroomstatus`.`KdRoomStatus`, '')) AS `2016-11-23 12:00:00`,
MAX(IF(`tp_tblstroomstatus`.`DateCheck` = '2016-11-23 14:00:00', `tp_tblstroomstatus`.`KdRoomStatus`, '')) AS `2016-11-23 14:00:00`,
MAX(IF(`tp_tblstroomstatus`.`DateCheck` = '2016-11-24 12:00:00', `tp_tblstroomstatus`.`KdRoomStatus`, '')) AS `2016-11-24 12:00:00`,
MAX(IF(`tp_tblstroomstatus`.`DateCheck` = '2016-11-24 14:00:00', `tp_tblstroomstatus`.`KdRoomStatus`, '')) AS `2016-11-24 14:00:00`,
MAX(IF(`tp_tblstroomstatus`.`DateCheck` = '2016-11-25 12:00:00', `tp_tblstroomstatus`.`KdRoomStatus`, '')) AS `2016-11-25 12:00:00`,
MAX(IF(`tp_tblstroomstatus`.`DateCheck` = '2016-11-25 14:00:00', `tp_tblstroomstatus`.`KdRoomStatus`, '')) AS `2016-11-25 14:00:00`,
MAX(IF(`tp_tblstroomstatus`.`DateCheck` = '2016-11-26 12:00:00', `tp_tblstroomstatus`.`KdRoomStatus`, '')) AS `2016-11-26 12:00:00`
FROM `tp_tblstroomstatus`
RIGHT OUTER JOIN `tp_tblmsroom` ON (`tp_tblstroomstatus`.`KdRoom` = `tp_tblmsroom`.`KdRoom`)
GROUP BY `tp_tblmsroom`.`KdRoom`
然後我試圖將其轉換爲:
SET @sql = NULL;
SELECT GROUP_CONCAT
(DISTINCT CONCAT(
'MAX(IF(`tp_tblstroomstatus`.`DateCheck` = ''',
`tp_tblstroomstatus`.`DateCheck`,
''', `tp_tblstroomstatus`.`KdRoomStatus`, '')) AS ',
`tp_tblstroomstatus`.`DateCheck`
)
) INTO @sql
FROM `tp_tblstroomstatus`
RIGHT OUTER JOIN `tp_tblmsroom` ON (`tp_tblstroomstatus`.`KdRoom` = `tp_tblmsroom`.`KdRoom`);
SET @sql = CONCAT('SELECT `tp_tblmsroom`.`KdRoom`, ', @sql, ' FROM `tp_tblstroomstatus`
RIGHT OUTER JOIN `tp_tblmsroom` ON (`tp_tblstroomstatus`.`KdRoom` = `tp_tblmsroom`.`KdRoom`) GROUP BY `tp_tblmsroom`.`KdRoom`');
但當嘗試運行MySQL的代碼,我得到這個錯誤。
you have an error in your SQL syntax....'SELECT GROUP_CONCAT(DISTICT...
有關更多的信息,我嘗試循環使用datetimepicker之間的datagridview生成新的列。這個我的VB.NET代碼:
Dim pDateCI As Date = dtpStartRoomRack.Text
Dim pDateCO As Date = dtpEndRoomRack.Text
Dim DayCount As Integer = DateDiff(DateInterval.Day, pDateCI, pDateCO)
For i = 0 To DayCount - 1
.Columns.Add(i, (Format(pDateCI, "yyyy/MM/dd") & " " & Format(pTimeCI, "HH:mm:ss"))) 'format pDateCI date use for call mysql data in checkdate column like 2016-11-21 14:00:00'
.Columns.Add(i, (Format(pDateCI.AddDays(1), "yyyy/MM/dd") & " " & Format(pTimeCO, "HH:mm:ss"))) 'format pDateCO date use for call mysql data in checkdate column like 2016-11-22 12:00:00'
pDateCI = pDateCI.AddDays(1)
Next
我該如何解決我的問題?在此先感謝:)
@Henry ...感謝交叉檢查我的問題,先生...... :) –
您應該編輯您的問題,併發布你得到:) – Henry
錯誤我得到一個錯誤,「你有一個錯誤的SQL語法....'SELECT GROUP_CONCAT(DISTICT ...「Sir ... –