请教如何将excel数据导入到sql server已有的表中
1个回答
2016-05-02 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
先在SQL中创建个table
create table student3
(
[sno] int not null primary key,
[sname] varchar(20) not null,
[sage] int,
);
打开一个新的excel,并添加些测试用的数据
添加Microsoft ActiveX Data Objects的引用,运行下面的代码
Sub DataFromExceltoSQLbyADO()
Dim Conn As New ADODB.Connection
Dim Sql As String
Dim i As Long
'change to your connection string
Conn.Open "Provider=SQLNCLI10;Server=xxx;Database=xxx;User Id=xxx;Password=xxx"
For i = 2 To 3
Sql = "insert into student3 values(" & Cells(i, 1) & ",'" & Cells(i, 2) & "', " & Cells(i, 3) & ")"
Conn.Execute (Sql)
Next i
Set Conn = Nothing
End Sub
create table student3
(
[sno] int not null primary key,
[sname] varchar(20) not null,
[sage] int,
);
打开一个新的excel,并添加些测试用的数据
添加Microsoft ActiveX Data Objects的引用,运行下面的代码
Sub DataFromExceltoSQLbyADO()
Dim Conn As New ADODB.Connection
Dim Sql As String
Dim i As Long
'change to your connection string
Conn.Open "Provider=SQLNCLI10;Server=xxx;Database=xxx;User Id=xxx;Password=xxx"
For i = 2 To 3
Sql = "insert into student3 values(" & Cells(i, 1) & ",'" & Cells(i, 2) & "', " & Cells(i, 3) & ")"
Conn.Execute (Sql)
Next i
Set Conn = Nothing
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询