c# - 尝试将 sql 数据导入 visual studio web 表单数据库

标签 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);

在以下数据库中:

(本地数据库)\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 查询可执行?

最佳答案

只需这样做:

 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 字段,你不需要比它更精确,所以直到分钟你应该没问题。

关于c# - 尝试将 sql 数据导入 visual studio web 表单数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44049721/

相关文章:

c# - 如何解决错误消息 : "Failed to map the path ' /'."

c# - 将 System.DateTime 转换为 NodaTime.ZonedDateTime

c# - SQL Server 连接字符串的连接池设置

c# - 创建动态匿名类型变量

sql-server - 如何以编程方式在 SQL Server 中启用 READ COMMITTED SNAPSHOT?

sql - 插入多个表

visual-studio - 如何修复 Visual Studio 中控制台的设置子系统?

sql-server - 使用 SQL Pivot 显示所有行,包括记录数为零的行

visual-studio - 如何获取 Visual Studio Community 2019 的 x64 native 工具开发人员命令提示符?

python 为什么有些模块是在 win 上定义的,而不是在 linux 上定义的