开发者

How do I update data using Linq-to-sql?

I need to update a datatabl开发者_如何学JAVAe using LINQToSql. Option Strict is ON.

Datatable name is Customer with fields customerID, customerName, SalesID. I need to update rows with SalesID = -1.


Another approach would be one which takes advantages of LinqToSql

Dim Customer = (From cust in db.Customers Where cust.SalesID = -1).GetEnumerator
While Customer.MoveNext
    Customer.Current.SomeField = NewValue
End While
db.SubmitChanges()

where db is a fully qualified DataContext object.

Update (with a dataset):

    Dim cmdEditCustomer as String = "UPDATE Customers SET Myvalue = @Myvalue WHERE SalesID = -1"

Dim CN as New SqlConnection(ConnString)
DACustomers.UpdateCommand = New SqlClient.SqlCommand(cmdEditCustomer)
DACustomers.UpdateCommand.Connection = CN
Dim param as New SqlParameter
param.ParameterName = "@Myvalue"
param.sqldbtype = Sqldbtype.String ( or whatever it is)
param.Direction = ParameterDirection.Input
param.Size = 15
Param.Value = "Whatever"
DaCustomers.UpdateCommand.Parameters.Add(param)

or

DACustomers.UpdateCommand(New System.Data.SqlClient.qlParameter(paramName,paramType,paramSize, _
paramDirection,ParamNullable,paramPrecision,paramScale,columnName,rowVersion,paramValue)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜