PC Review


Reply
Thread Tools Rate Thread

C# Prepared Statements

 
 
5By5
Guest
Posts: n/a
 
      28th Jul 2005
Hi all,

Can someone point me to an example of prepared statements being used in C#
ado.net? the MSDN site has examples using VB and my documentation in VS 2005
says "to be filled in" or something equally useful.

thanks in advance,
Pat


 
Reply With Quote
 
 
 
 
William \(Bill\) Vaughn
Guest
Posts: n/a
 
      28th Jul 2005
Do you mean the "Prepare" method on the (Sql)Command class? I'm documenting
that this week.

--
____________________________________
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.
__________________________________

"5By5" <(E-Mail Removed)> wrote in message
news:dc95fe$g5f$(E-Mail Removed)...
> Hi all,
>
> Can someone point me to an example of prepared statements being used in C#
> ado.net? the MSDN site has examples using VB and my documentation in VS
> 2005 says "to be filled in" or something equally useful.
>
> thanks in advance,
> Pat
>



 
Reply With Quote
 
Patrick McGovern
Guest
Posts: n/a
 
      28th Jul 2005

"William (Bill) Vaughn" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Do you mean the "Prepare" method on the (Sql)Command class? I'm
> documenting that this week.


that's exactly what i mean! this is the functionality that allows me to
write a statement like "select * from project where id=?" right?

>
> --
> ____________________________________
> 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.
> __________________________________
>
> "5By5" <(E-Mail Removed)> wrote in message
> news:dc95fe$g5f$(E-Mail Removed)...
>> Hi all,
>>
>> Can someone point me to an example of prepared statements being used in
>> C# ado.net? the MSDN site has examples using VB and my documentation in
>> VS 2005 says "to be filled in" or something equally useful.
>>
>> thanks in advance,
>> Pat
>>

>
>



 
Reply With Quote
 
William \(Bill\) Vaughn
Guest
Posts: n/a
 
      29th Jul 2005
The Prepare function is a throwback to the ODBC drivers that needed this to
tell the interface to "prepare" the SQL for execution. It's not needed in
ADO.NET and as far as I can tell (although my experiments aren't complete on
2.0) it does nothing (it's a noop) in the SqlClient provider.
If you want to build parameter queries you can, but it has nothing to do
with Prepare. Try building a Command object and set the Command text to
include named parameter markers
SELECT Author FROM Authors WHERE au_id = @idwanted
Next, setup a Parameters collection on the Command to manage the Parameter
cmd.Parameters.AddWithValue("@idwanted",15)

and execute.

I discuss this in my ADO.NET book (on the shelves now). While it does not
cover 2.0 it does cover these basics.

hth

--
____________________________________
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.
__________________________________

"Patrick McGovern" <(E-Mail Removed)> wrote in message
news:dcbdt7$587$(E-Mail Removed)...
>
> "William (Bill) Vaughn" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Do you mean the "Prepare" method on the (Sql)Command class? I'm
>> documenting that this week.

>
> that's exactly what i mean! this is the functionality that allows me to
> write a statement like "select * from project where id=?" right?
>
>>
>> --
>> ____________________________________
>> 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.
>> __________________________________
>>
>> "5By5" <(E-Mail Removed)> wrote in message
>> news:dc95fe$g5f$(E-Mail Removed)...
>>> Hi all,
>>>
>>> Can someone point me to an example of prepared statements being used in
>>> C# ado.net? the MSDN site has examples using VB and my documentation in
>>> VS 2005 says "to be filled in" or something equally useful.
>>>
>>> thanks in advance,
>>> Pat
>>>

>>
>>

>
>



 
Reply With Quote
 
Patrick McGovern
Guest
Posts: n/a
 
      29th Jul 2005
Bill,

thanks for the information. I do want parameterized queries. i was looking
at it from a Java perspective where we call these prepared statements.

Book? Book? well let me go check that out. It's the hitchhiker's guide one?

i'm very new to .net and so far i'm pretty pleased with everything i'm
finding. the wealth of resources is somewhat staggering.


thanks for the information and the quick responses,
Pat


"William (Bill) Vaughn" <(E-Mail Removed)> wrote in message
news:e8Y9Zm%(E-Mail Removed)...
> The Prepare function is a throwback to the ODBC drivers that needed this
> to tell the interface to "prepare" the SQL for execution. It's not needed
> in ADO.NET and as far as I can tell (although my experiments aren't
> complete on 2.0) it does nothing (it's a noop) in the SqlClient provider.
> If you want to build parameter queries you can, but it has nothing to do
> with Prepare. Try building a Command object and set the Command text to
> include named parameter markers
> SELECT Author FROM Authors WHERE au_id = @idwanted
> Next, setup a Parameters collection on the Command to manage the Parameter
> cmd.Parameters.AddWithValue("@idwanted",15)
>
> and execute.
>
> I discuss this in my ADO.NET book (on the shelves now). While it does not
> cover 2.0 it does cover these basics.
>
> hth
>
> --
> ____________________________________
> 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.
> __________________________________
>
> "Patrick McGovern" <(E-Mail Removed)> wrote in message
> news:dcbdt7$587$(E-Mail Removed)...
>>
>> "William (Bill) Vaughn" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Do you mean the "Prepare" method on the (Sql)Command class? I'm
>>> documenting that this week.

>>
>> that's exactly what i mean! this is the functionality that allows me
>> to write a statement like "select * from project where id=?" right?
>>
>>>
>>> --
>>> ____________________________________
>>> 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.
>>> __________________________________
>>>
>>> "5By5" <(E-Mail Removed)> wrote in message
>>> news:dc95fe$g5f$(E-Mail Removed)...
>>>> Hi all,
>>>>
>>>> Can someone point me to an example of prepared statements being used in
>>>> C# ado.net? the MSDN site has examples using VB and my documentation in
>>>> VS 2005 says "to be filled in" or something equally useful.
>>>>
>>>> thanks in advance,
>>>> Pat
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
William \(Bill\) Vaughn
Guest
Posts: n/a
 
      29th Jul 2005
No, the HHG for ADO.NET 2.0 is not done yet... (I keep stopping to answer
questions)
I was referring to the ADO.NET Examples and Best Practices For C#
Programmers (Apress).
Sorry to hear about the Java thing... I think there are shots for that now.

--
____________________________________
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.
__________________________________

"Patrick McGovern" <(E-Mail Removed)> wrote in message
news:dcdmlu$nbt$(E-Mail Removed)...
> Bill,
>
> thanks for the information. I do want parameterized queries. i was looking
> at it from a Java perspective where we call these prepared statements.
>
> Book? Book? well let me go check that out. It's the hitchhiker's guide
> one?
>
> i'm very new to .net and so far i'm pretty pleased with everything i'm
> finding. the wealth of resources is somewhat staggering.
>
>
> thanks for the information and the quick responses,
> Pat
>
>
> "William (Bill) Vaughn" <(E-Mail Removed)> wrote in message
> news:e8Y9Zm%(E-Mail Removed)...
>> The Prepare function is a throwback to the ODBC drivers that needed this
>> to tell the interface to "prepare" the SQL for execution. It's not needed
>> in ADO.NET and as far as I can tell (although my experiments aren't
>> complete on 2.0) it does nothing (it's a noop) in the SqlClient provider.
>> If you want to build parameter queries you can, but it has nothing to do
>> with Prepare. Try building a Command object and set the Command text to
>> include named parameter markers
>> SELECT Author FROM Authors WHERE au_id = @idwanted
>> Next, setup a Parameters collection on the Command to manage the
>> Parameter
>> cmd.Parameters.AddWithValue("@idwanted",15)
>>
>> and execute.
>>
>> I discuss this in my ADO.NET book (on the shelves now). While it does not
>> cover 2.0 it does cover these basics.
>>
>> hth
>>
>> --
>> ____________________________________
>> 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.
>> __________________________________
>>
>> "Patrick McGovern" <(E-Mail Removed)> wrote in message
>> news:dcbdt7$587$(E-Mail Removed)...
>>>
>>> "William (Bill) Vaughn" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> Do you mean the "Prepare" method on the (Sql)Command class? I'm
>>>> documenting that this week.
>>>
>>> that's exactly what i mean! this is the functionality that allows me
>>> to write a statement like "select * from project where id=?" right?
>>>
>>>>
>>>> --
>>>> ____________________________________
>>>> 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.
>>>> __________________________________
>>>>
>>>> "5By5" <(E-Mail Removed)> wrote in message
>>>> news:dc95fe$g5f$(E-Mail Removed)...
>>>>> Hi all,
>>>>>
>>>>> Can someone point me to an example of prepared statements being used
>>>>> in C# ado.net? the MSDN site has examples using VB and my
>>>>> documentation in VS 2005 says "to be filled in" or something equally
>>>>> useful.
>>>>>
>>>>> thanks in advance,
>>>>> Pat
>>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting computer prepared for Vista =?Utf-8?B?TC5K?= Windows Vista Installation 10 4th Jun 2007 04:34 AM
Be prepared... ArjanDotOrg Freeware 0 10th Oct 2005 11:14 AM
Prepared Statement? Phill Microsoft Access VBA Modules 1 6th Oct 2004 10:47 PM
Prepared Execution =?Utf-8?B?QXJyIFM=?= Microsoft C# .NET 0 4th Feb 2004 02:21 PM
Prepared Execution =?Utf-8?B?QXJyIFM=?= Microsoft Dot NET Framework 0 4th Feb 2004 02:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:46 AM.