Home > Blockchain >  which is the best and fast command parameters in oledb in vb.net
which is the best and fast command parameters in oledb in vb.net

Time:09-20

Dear All Programmer,

which is the best and fast parameter command in oledb in vb.net please explain the details with the option code below because I want to use the CRUD application in the access database so that I do not become wrong in applying the code

Thanks

cmd.Parameters.Add(New OleDbParameter("Item1", TextBox1.Text))
cmd.Parameters.AddWithValue("Item1", TextBox1.Text)
cmd.Parameters.Add("Item1", OleDbType.VarChar).Value = TextBox1.Text

CodePudding user response:

Well, speed of the parameters is the WRONG word and concept here.

the CPU has stupid amounts of processing. The speed or time of the parameters is not going to be significant here. (what will take all the time and does matter is the speed of the data engine ONCE it starts to pull data - that will take 10,000 times longer. As a result, the issue is not speed of adding parameters here and it not going to make a difference.

but, what is a better choice from a developer point of view?

What is a better choice when attempting to use parameters?

Without question - your 3rd example is the better choice:

eg this one:

cmd.Parameters.Add("Item1", OleDbType.VarChar).Value = TextBox1.Text

In fact, quite a bit of confusing exists in this regards. There are notes, comments, and even articles suggesting to NOT use .Add. But, in fact, they mean to NOT use .Add overload in which you add, and use the 2nd value for the "value". In that case, this can confuse the parameters, since the enumeration of the sqlDBTypes also can be a integer, and it not clear if you adding a int value, or trying to use a sqlDBtype.

but, WHEN you use .Value as per 3rd example, .net will not ever be confused, and thus using your last value with enjoyment of STRONG TYPED parameter conversion is the best choice of your example code bits.

That 3rd form of .Add is not and WAS NEVER deprecated.

  • Related