Ado.net -Parameter problem

  • Thread starter Thread starter Agnes
  • Start date Start date
A

Agnes

I create stored procedure which search the currencyinformation from sql
server
In my vb.net coding, i will pass the following paramter
Dim prmCurr_Code As New SqlParameter("@searchcode",
SqlDbType.VarChar, 3)

Problem , if the user input "USDX" , this parameter will be passed as "USD"
( since I set it as varchar 3), and the query will give me the "correct"
information, It will make a strange bug.
How should I solve it ? , Should I check the length of input currency before
?
Please give some comment
 
I think you naswere your own question. Why limit the Parameter to anything
less than 50 characters ?

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
 
Agnes,

Why you call this a bug? In other words can you tell me what it should do
when it was in your opinion not a bug?

I cannot find much other behaviour than as it does. It gives from a string
only the first 3 positions to the parameter.

Cor
 
When supplying the size parameter, you should put whatever it's defined as in
the database, but your user interface should also take account of this.
Your application should know the maximum length of strings, especially when
they are "codes" that are deliberately truncated, like the currency symbols -
but if not by hardcoding, it should certainly find out, rather than trying to
relate to what the input might be.
If someone puts "USDX", then probably the framework is truncating it to
"USD" before passing it to SQL server because you've told it that it's length
is 3. And SQL sever's therefore returning the row for "USD", hence like you
say, 'falsely' correct. What you should do instead, is to raise an error to
the user telling them that their input is too big. Either that, or have a
textbox that can only contain 3 characters.

Then they won't realise half way through that they've done it wrong but
wonder why it didn't alert them to this fact.
 
Back
Top