简体   繁体   English

使用 vb.net 更新 SQL Server 数据库中的表

[英]Update tables in a SQL Server database by using vb.net

I have a SQL Server database with two tables:我有一个包含两个表的 SQL Server 数据库:

tblEmp with columns:带有列的tblEmp

EmpNum, EmpName, EmpAge, EmpAdress, EmpDegree, EmpJobTitle, EmpPhone 

and the column UnitID that used to set the relationship between the two tables以及用于设置两个表之间关系的列UnitID

tblUnits with columns:带有列的tblUnits

UnitID, UnitName

In VB the code is:在VB中的代码是:

Public Class Form1
    Dim con As New SqlConnection("server=.....etc")
    Dim adapter As SqlDataAdapter
    Dim dt As New DataTable
    Dim cmdb As New SqlCommandBuilder

    Private Sub btnUpdate_Click.......
        Dim row As DataRow = dt.Rows.Find(txtNum.Text)
        row(0) = txtNum.Text
        row(1) = txtName.Text
        row(2) = txtAge.Text
        row(3) = txtAdress.Text
        row(4) = txtDegree.Text
        row(5) = txtJob.Text
        row(6) = txtPhone.Text
        row(7) = cmbunits.Text
        cmdb = New SqlCommandBuilder(adapter)
        adapter.Update(dt)

I get this error:我收到此错误:

Additional information: Dynamic SQL generation is not supported against multiple base tables.附加信息:不支持针对多个基表生成动态 SQL。

A command builder uses the query in the SelectCommand of your data adapter to generate the other commands.命令构建器使用数据适配器的SelectCommand中的查询来生成其他命令。 That can only happen under certain circumstances.这只能在某些情况下发生。 One of those circumstances is that the query does not involve multiple tables.其中一种情况是查询不涉及多个表。 The error message indicates that that is not true in your case.错误消息表明您的情况并非如此。 You need to create the UpdateCommand , etc, yourself.您需要自己创建UpdateCommand等。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM