Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server DataTable.update-_Sql Server_Vb.net - Fatal编程技术网

Sql server DataTable.update-

Sql server DataTable.update-,sql-server,vb.net,Sql Server,Vb.net,我对.NET很陌生,所以这可能是最基本的东西 这是我的密码: adapter1 = New SqlDataAdapter("SELECT top 0 * FROM [aTable]", connection) cb = New SqlCommandBuilder(adapter1) adapter1.InsertCommand = cb.GetInsertCommand adapter1.Update(dataSet1, "[aT

我对.NET很陌生,所以这可能是最基本的东西

这是我的密码:

        adapter1 = New SqlDataAdapter("SELECT top 0 * FROM [aTable]", connection)
        cb = New SqlCommandBuilder(adapter1)
        adapter1.InsertCommand = cb.GetInsertCommand 
        adapter1.Update(dataSet1, "[aTable]") 
基本上,我想做的是插入到这个表中。但是,我要插入的某些值可能已经存在于表aTable中的其他行中,但1列不同。但是,我不想更新任何行,而是始终插入新行。但到目前为止,我总是会得到一个更新的旧行具有类似的值

如何在.update()-函数中确定哪一列应该在WHERE子句中?或者有没有更好的方法


谢谢

是的,可以使用指定更新命令的外观。看看这个例子:

' Create the UpdateCommand.'
Dim command As SqlCommand command = New SqlCommand( _
    "UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName " & _
    "WHERE CustomerID = @oldCustomerID", connection)

' Add the parameters for the UpdateCommand.'
command.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID")
command.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 40, "CompanyName")
Dim parameter As SqlParameter = command.Parameters.Add( _
    "@oldCustomerID", SqlDbType.NChar, 5, "CustomerID")
parameter.SourceVersion = DataRowVersion.Original

adapter.UpdateCommand = command