-3

我想要代码做的是从文本框 ID 号中获取输入,然后获取 ID 所属的记录并将其插入到另一个表中,但是我更改了 SQL 语句,当我按下按钮时仍然没有任何反应

Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click

Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source= " & Server.MapPath("~/Members.mdb"))

Dim cmd As New OleDbCommand

 Dim i As Integer

cmd.Connection = con

 cmd.CommandType = Data.CommandType.Text

cmd.CommandText = "insert into kfupm_stu_visitor (kfupm_stu_id, stu_name, kfupm_maj_id, kfupm_dep_id, level_id) select * from kfupm_stu where fupm_stu_id like @kfupm_stu_id"
        cmd.Parameters.Add("KFUPM_STU_ID", OleDbType.Integer).Value = "%" & txtSTU_ID.Text & "%"
        con.Open()

        Try
            i = cmd.ExecuteNonQuery()
        Catch ex As Exception

            Response.Redirect("msgpage.aspx?id=1")
        Finally
            con.Close()
            End Try

        Response.Redirect("msgpage.aspx?id=2")

    End Sub
4

1 回答 1

7

如果您使用查询来填充列,则不需要该values (...)部分。它应该只是:

insert into kfupm_stu_visitor 
(kfupm_stu_id, stu_name, kfupm_maj_id, kfupm_dep_id, level_id)
select * from 
kfupm_stu where fupm_stu_id like @kfupm_stu_id

当然,这假设中的列与列表kfupm_stu中的列完全匹配insert into

于 2012-12-27T21:03:24.443 回答