发新话题
打印

[数据库] 创建新表并插入内容问题

创建新表并插入内容问题

Private Sub Command1_Click()
Dim cn As New ADODB.Connection
  cn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=教学管理系统;Data Source=DL"
  cn.Execute ("Create   Table " & from1.Caption)
  cn.Execute ("select * into " & from2.Caption & " from " & from1.ss & " where 学期 ='" & from1.Combo3.Text & "'")
End Sub
程序目的:当前窗体中有一个由两张表拼成的新表datagrid2,datagrid2中的内容是以from1中字符串ss为名字的课程表的某一学期的内容。
我希望点击command1,在数据库中建立一个以from2.caption为名字的新表,并且内容就是datagrid2中的内容
请各位帮下忙

TOP

这样写肯定不行
先要取到datagrid2所有列的信息
然后创建表结构
cn.Execute ("Create   Table " & from1.Caption)
应写成
cn.Execute ("Create   Table " & from1.Caption &" (字段1 字段类型,字段2 字段类型,……)")
换个头像,看见广告就眼红,直接封ID。

TOP

哦 谢谢!我敲上代码:
cn.Execute ("Create   Table " & from1.Caption &" (课程编码 nvarchar,课程名称 nvarchar, 性质 nvarchar,,……)")
   cn.Execute ("select * into " & from2.Caption & " from " & from1.ss & " where 学期 ='" & from1.Combo3.Text & "'")      
可是总说:第1行:“:”附近语法错误,这是什么意思阿,指向第一句,这是什么错误阿,语句里也没有冒号阿

TOP

nvarchar在access中应当使用text,注意,字符要加上长度
如:课程编码 text(10)
换个头像,看见广告就眼红,直接封ID。

TOP

发新话题