如何创建两个表?

wfl_1000 2009-02-26 10:44:28
conn1 = New SqlConnection(ConnectionString)
If (strSecond > 19 And strSecond <= 59) Or (strSecond >= 0 And strSecond <= 7) Then

If conn1.State = ConnectionState.Open Then
conn1.Close()
End If
conn1.ConnectionString = ConnectionString
conn1.Open()
sql1 = "CREATE TABLE " + theName1 + "(Time NVARCHAR(50) Null,myid NVARCHAR(50) Null,myname NVARCHAR(50) NOT Null,myaddress NVARCHAR(50) Null)"
cmd1 = New SqlCommand(sql1, conn1)
上面这段代码只可以创建一个表。但是我想创建两个表,为什么下面这段不可以?

conn1 = New SqlConnection(ConnectionString)
conn2 = New SqlConnection(ConnectionString)

If (strSecond > 19 And strSecond <= 59) Or (strSecond >= 0 And strSecond <= 7) Then

If conn1.State = ConnectionState.Open Then
conn1.Close()
End If
conn1.ConnectionString = ConnectionString
conn1.Open()
sql1 = "CREATE TABLE " + theName1 + "(Time NVARCHAR(50) Null,myid NVARCHAR(50) Null,myname NVARCHAR(50) NOT Null,myaddress NVARCHAR(50) Null)"
cmd1 = New SqlCommand(sql1, conn1)


If conn2.ConnectionString = ConnectionString Then
conn2.Close()
End If
conn2.ConnectionString = ConnectionString
conn2.Open()
sql2 = "CREATE TABLE " + theName2 + "(Time NVARCHAR(50) Null,myid NVARCHAR(50) Null,myname NVARCHAR(50) NOT Null,myaddress NVARCHAR(50) Null)"
cmd2 = New SqlCommand(sql2, conn2)
...全文
56 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
晓轩 2009-02-26
  • 打赏
  • 举报
回复
conn1 = New SqlConnection(ConnectionString)
If (strSecond > 19 And strSecond <= 59) Or (strSecond >= 0 And strSecond <= 7) Then

If conn1.State = ConnectionState.Open Then
conn1.Close()
End If
conn1.ConnectionString = ConnectionString
conn1.Open()
sql1 = "CREATE TABLE " + theName1 + "(Time NVARCHAR(50) Null,myid NVARCHAR(50) Null,myname NVARCHAR(50) NOT Null,myaddress NVARCHAR(50) Null)"
cmd1 = New SqlCommand(sql1, conn1)
cmd1.ExecuteNonQuery
sql1 = "CREATE TABLE " + theName2 + "(Time NVARCHAR(50) Null,myid NVARCHAR(50) Null,myname NVARCHAR(50) NOT Null,myaddress NVARCHAR(50) Null)"
cmd1.commandtext=sql1
cmd1.ExecuteNonQuery
wfl_1000 2009-02-26
  • 打赏
  • 举报
回复
谢谢:xiaoxuanZhu 的及时回复!问题解决了!多谢大家的支持!
wuyq11 2009-02-26
  • 打赏
  • 举报
回复
用二楼方法就可,定义一个SqlConnection就可。

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧