Re: Parameters Question

Tech-Archive recommends: Fix windows errors by optimizing your registry



Uh actually yes it is. I've done it this way for quite some time now.
Here's a snippet of code that works like a charm:

Dim insertSQL As String = _
"INSERT INTO tblOrders " & _
"(Customer,Address,Add2,City,ST,Zip,Phone,Email," & _
"ProductName,Quantity,PriceEach) " & _
"VALUES(@CustName,@Add1,@Add2,@City,@ST,@Zip," & _
"@Phone,@Email,@Product,@Qty,@PriceEach)"

Dim cmdInsert As New OleDb.OleDbCommand(insertSQL, con)

With cmdInsert.Parameters
.Add(New OleDb.OleDbParameter("@CustName", OrderDetails.Customer))
.Add(New OleDb.OleDbParameter("@Add1", OrderDetails.Address1))
.Add(New OleDb.OleDbParameter("@Add2", OrderDetails.Address2))
.Add(New OleDb.OleDbParameter("@City", OrderDetails.City))
.Add(New OleDb.OleDbParameter("@ST", OrderDetails.State))
.Add(New OleDb.OleDbParameter("@Zip", OrderDetails.ZipCode))
.Add(New OleDb.OleDbParameter("@Phone", OrderDetails.Phone))
.Add(New OleDb.OleDbParameter("@Email", OrderDetails.Email))
.Add(New OleDb.OleDbParameter("@Product", OrderDetails.Product))
.Add(New OleDb.OleDbParameter("@Qty", OrderDetails.Quantity))
.Add(New OleDb.OleDbParameter("@PriceEach", OrderDetails.PriceEach))
End With


"William (Bill) Vaughn" <billvaRemoveThis@xxxxxxxxxx> wrote in message
news:u2VNa01VFHA.3588@xxxxxxxxxxxxxxxxxxxxxxx
> Ah no. The OleDB parameter marker is a "?" for the JET provider. Yes, you
> can name these parameters in the Parameter collection, but the name is not
> used to match the parameter in the query string.
>
> --
> ____________________________________
> William (Bill) Vaughn
> Author, Mentor, Consultant
> Microsoft MVP
> www.betav.com/blog/billva
> www.betav.com
> Please reply only to the newsgroup so that others can benefit.
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> __________________________________
>
> "Scott M." <s-mar@xxxxxxxxxxxxx> wrote in message
> news:O94GfA1VFHA.132@xxxxxxxxxxxxxxxxxxxxxxx
>> In ADO.NET, you don't use the question mark to indicate a parameter
>> value, you use @paramaterName as in:
>>
>> "SELECT * FROM tblUsers WHERE User=@user"
>>
>> Check out this for more info:
>>
>> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdataoledboledbparameterclasstopic.asp
>>
>>
>>
>>
>> "ltt19" <ltt19@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>> news:1A0A7F63-C0DD-45BF-BB7C-11675BB479CC@xxxxxxxxxxxxxxxx
>>> Hi,
>>>
>>> I'm new to ADO.net, even new to Databases access, and I have a
>>> CommandText
>>> that is useful to all of my tables, however I can not find the
>>> approppiate
>>> use of paramnter to do this. Like:
>>>
>>> "SELECT * FROM ?"
>>>
>>> I'm using an Acess database and the OLEDB.
>>>
>>> Another Question, How can I use paramter to Select Fields that can be
>>> chosen by the user? Like a "SELECT ? ? FROM Music" but I don't know wich
>>> are
>>> these "?" and how many will have.
>>>
>>> Hope that I was clear.
>>>
>>> Any help would be very useful.
>>> Thanks in advance.
>>>
>>
>>
>
>


.