PC Review


Reply
Thread Tools Rate Thread

What is the C# equivilant to the following in vb.net?

 
 
Trint Smith
Guest
Posts: n/a
 
      29th Dec 2004
This is how I did this sql server 2000 string in vb.net:

"FROM TBL_TravelMain WHERE TravelMain_Mlv = '" & MLVTrimString & "'"

In C# you can't use the & something &.
How do I put this in C#, or what do I replace the & with?
Thanks,
Trint

.Net programmer
(E-Mail Removed)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      29th Dec 2004
Trint,

You maybe did this in VBNet, however in that it is as wrong as in every
dotNet language
it has to be

.....FROM TBL_TravelMain WHERE TravelMain_Mlv = @MLVTrimString"

And than use the XXXcommand.parameters, here the link for SQL
http://msdn.microsoft.com/library/de...eterstopic.asp

I hope this helps?

Cor


 
Reply With Quote
 
mphanke
Guest
Posts: n/a
 
      29th Dec 2004
Hi Trint,
> This is how I did this sql server 2000 string in vb.net:
>
> "FROM TBL_TravelMain WHERE TravelMain_Mlv = '" & MLVTrimString & "'"

try

"FROM TBL_TravelMain WHERE TravelMain_Mlv = '" + MLVTrimString + "'"


Martin
 
Reply With Quote
 
=?Utf-8?B?QnJpYW4gQnJvd24=?=
Guest
Posts: n/a
 
      29th Dec 2004
Trint,

Replace the & with + signs. Don't forget to terminate the line with ;

Hope this helps.


 
Reply With Quote
 
Anders Norås [MCAD]
Guest
Posts: n/a
 
      29th Dec 2004
> "FROM TBL_TravelMain WHERE TravelMain_Mlv = '" & MLVTrimString & "'"
>
> In C# you can't use the & something &.
> How do I put this in C#, or what do I replace the & with?


The C# equivilant to & is +. However, the code in your example is vunerable
to SQL injection attacks. You should use a parameterized query instead. The
following example shows how to use SqlCommand and SqlParameter:

SqlCommand cmd=new SqlCommand();
cmd.CommandText="SELECT * FROM TBL_TravelMain WHERE
TravelMain_Mlv=@TravelMain";
cmd.Parameters.Add("@TravelMain",SqlDbType.VarChar).Value=MLVTrimString;

Anders Norås
http://dotnetjunkies.com/weblog/anoras/


 
Reply With Quote
 
Trint Smith
Guest
Posts: n/a
 
      29th Dec 2004
Cor,
This is in a SQL statement in C# and the equivilant to "&" turns out to
be "+".
Thanks,
Trinity

.Net programmer
(E-Mail Removed)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Anders Norås [MCAD]
Guest
Posts: n/a
 
      29th Dec 2004
> Cor,
> This is in a SQL statement in C# and the equivilant to "&" turns out to
> be "+".


Trinity,
I think Cor is pointing out that your code does not follow best practices
for data access. I has a SQL injection vunerablity.
SQL injection is a technique for exploitiong applications that use client
supplied data in SQL queries without handling potentially dangerous user
input. If the variable MLVTrimString in your example originates from a input
field or similar and the database user has sufficient privelidges, an
attacker can enter '; DROP TABLE TBL_TravelMain -- into the input field and
actually delete your entire database table.
You should learn how to use classes described on the page Cor referred to so
that you avoid SQL injection attacks.

Anders Norås
http://dotnetjunkies.com/weblog/anoras/


 
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
.NET equivilant of isnumeric moondaddy Microsoft VB .NET 8 23rd Aug 2006 09:32 PM
Re: INKEY$ equivilant Wayne M J Microsoft VB .NET 0 2nd Jan 2004 06:18 AM
Re: LinkLists Equivilant Jay B. Harlow [MVP - Outlook] Microsoft VB .NET 11 21st Nov 2003 03:23 PM
Re: LinkLists Equivilant Herfried K. Wagner [MVP] Microsoft VB .NET 0 19th Nov 2003 08:36 PM
Re: LinkLists Equivilant David Williams Microsoft VB .NET 1 19th Nov 2003 08:24 PM


Features
 

Advertising
 

Newsgroups
 


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