Preparing command with the Data Access Application

Topics: Mobile Client Software Factory
Aug 29, 2006 at 6:43 AM
originally posted by: albertom2u

How should I prepare a command to be called several times with the ExecuteNonQuery method?

Would this be the proper way to prepare a command and execute a prepared command?

Dim PickingListCommand As DbCommand = sqlDB.DbProviderFactory.CreateCommand
With PickingListCommand
.CommandText = "UPDATE ... SET ... WHERE myField = " & sqlDB.BuildParameterName("MyParameter")
.CommandType = CommandType.Text
.Parameters.Add(sqlDB.CreateParameter("MyParameter", DbType.String, 50, Nothing))
End With
Dim PickingListParameters() As DbParameter = {sqlDB.CreateParameter("MyParameter", "MyValue")}
sqlDB.ExecuteNonQuery(PickingListCommand, PickingListParameters)

Can I pass Nothing as the value when preparing the command?

Wouldn't it be interesting to have a PrepareCommand method, that would accept a string SQL instruction and a DBParameters array as arguments, that would prepare the command?

Thanks in advance,

Alberto Silva