简体   繁体   English

如何使用VBA将Excel单元格中的datetime值添加到SQL表中

[英]how to add datetime value from excel cell using VBA into SQL table

Can anyone help? 有人可以帮忙吗?

strSql = "INSERT INTO EmailRT (rs.Fields(0).Value, rs.Fields(1).Value) " & _
        " VALUES (" & _
        "'" & shtSheetToWork.Cells(2, 1).Value & "', " & _
        "'" & shtSheetToWork.Cells(2, 2).Value & "')"

In cell (2,2), the value is 21/10/2014 22:32 how do i add this to Sql table into column rs.Fields(1).Value whose data type is datetime 在单元格(2,2)中,值为21/10/2014 22:32如何将其添加到Sql表中的rs.Fields(1)列中,其数据类型为datetime

1) You can format the cell as you need (in Ctrl+1 ). 1)您可以根据需要设置单元格的格式(在Ctrl + 1中 )。 And then use shtSheetToWork.Cells(2, 1).Text 然后使用shtSheetToWork.Cells(2, 1).Text

2) You can use VBA Format. 2)您可以使用VBA格式。 Format(shtSheetToWork.Cells(2, 1).Text, "yyyyMMdd")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Excel:将单元格值传递给VBA SQL语句 - Excel: Passing Cell Value to VBA SQL Statement 如何使用从SQL表读取数据并从中生成EXCEL报告的ASP.NET C#代码/程序向EXCEL单元格添加单引号? - How do I add single quote to an EXCEL cell using ASP.NET C# code/program that reads data from an SQL Table and producing an EXCEL report from it? 你如何使用 VBA JOIN 从 Excel 表更新 SQL 表 - How do you UPDATE SQL Table from Excel Table using VBA JOIN 如何从SQL表获取单元格值? - How to get a cell value from SQL table? SQL表编辑:在表中添加DateTime值 - SQL Table Edit: Add DateTime value in table 使用 Excel VBA 将表从 SQL 导入到 Access - Import table from SQL to Access using Excel VBA 如何使用VBA代码从Excel数据更新Sql Server表? - How to update Sql server table from excel data using vba code? Access + VBA + SQL - 如何将多个查询导出到一个 Excel 工作簿中,但是,多个工作表使用表中的条件 - Access + VBA + SQL - How to export multiple queries into one excel Workbook, but, multiple Worksheet using the criteria from a table 如何使用Excel VBA将日期循环到此sql表中 - How can I loop the date into this sql table using Excel VBA 如何在VBA上的SQL查询中将单元格Excel单元格引用定义为参数? - how to define cell excel cell reference as a parameter in SQL query on VBA?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM