尝试将sql数据导入Visual Studio Web表单数据库

时间:2017-05-18 13:54:07

标签: c# sql-server visual-studio

我试图导入以下数据:

    INSERT INTO shifts (shift_id, shift_facility_id, shift_user_id, shift_start_time, shift_replacement, shift_request_replacement) VALUES
(1, 57, '1', '2017-05-19 00:00:00.000000', NULL, NULL),
(2, 57, '1', '2017-05-19 12:00:00.000000', NULL, NULL),
(3, 57, '1', '2017-05-20 00:00:00.000000', NULL, NULL),
(4, 57, '1', '2017-05-20 12:00:00.000000', NULL, NULL),
(5, 57, '2', '2017-05-21 00:00:00.000000', NULL, NULL),
(62, 59, '6', '2017-05-19 00:00:00.000000', NULL, NULL),
(64, 60, '4', '2017-05-19 00:00:00.000000', NULL, NULL);

在以下数据库中:

(的LocalDB)\ MSSQLLocalDB

CREATE TABLE shifts (

shift_id int NOT NULL, 
  shift_facility_id int NOT NULL,
  shift_user_id varchar(64) NOT NULL,
  shift_start_time datetime NOT NULL,
  shift_replacement varchar(64) DEFAULT NULL,
  shift_request_replacement varchar(65) DEFAULT NULL
) 

但我一直收到错误

Conversion failed when converting date and/or time from character string.

我试图从查询中删除每个'(它修复了之前的问题一次),但这次没有成功。

错误是由以下部分产生的:

'2017-05-20 12:00:00.000000'

有谁知道如何使这个SQL查询可执行?

1 个答案:

答案 0 :(得分:3)

这样做:

 INSERT INTO shifts (shift_id, shift_facility_id, shift_user_id, shift_start_time, shift_replacement, shift_request_replacement) 
 VALUES
            (1, 57, '1', '2017-05-19 00:00:00', NULL, NULL),
            (2, 57, '1', '2017-05-19 12:00:00', NULL, NULL),
            (3, 57, '1', '2017-05-20 00:00:00', NULL, NULL),
            (4, 57, '1', '2017-05-20 12:00:00', NULL, NULL),
            (5, 57, '2', '2017-05-21 00:00:00', NULL, NULL),
            (62, 59, '6', '2017-05-19 00:00:00', NULL, NULL)
            (64, 60, '4', '2017-05-19 00:00:00', NULL, NULL);

你有一个datetime字段,你不需要比你应该没有的那么精确的精确度。