Exact searching


Author
Message
Thomas Holste
Thomas Holste
Advanced StrataFrame User (536 reputation)Advanced StrataFrame User (536 reputation)Advanced StrataFrame User (536 reputation)Advanced StrataFrame User (536 reputation)Advanced StrataFrame User (536 reputation)Advanced StrataFrame User (536 reputation)Advanced StrataFrame User (536 reputation)Advanced StrataFrame User (536 reputation)Advanced StrataFrame User (536 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
Hi there,

in one of my BOs ("LieferBO") I added a get-method I took from the help-file

and modified it to myBO-name and field-name.

[code]

Dim loCommand As New SqlCommand()

loCommand.CommandText = "SELECT COUNT(*) FROM liefer WHERE adresse = @pAdresse"

loCommand.Parameters.Add("@pAdresse", SqlDbType.VarChar)

loCommand.Parameters("@pAdresse").Value = cAdresse

Return CType(Me.ExecuteScalar(loCommand), Integer)

[/code

But now I have the following problem which I can't solve by myself:

There are, for example the following records with the field "adresse" which is a char(6)-field:

B-M

BALM

BZ

I want to search, if there is a record with "BAL", which would be a valid new value, but the method returns 1 because it finds the "BALM"-record. I tried changing the var cAdresse to cAdresse.padr(6," ") which always worked with VFP-Views, but not here.

Can somebody advise me how this can be done?

Thanks in advance

Thomas

Replies
Thomas Holste
Thomas Holste
Advanced StrataFrame User (536 reputation)Advanced StrataFrame User (536 reputation)Advanced StrataFrame User (536 reputation)Advanced StrataFrame User (536 reputation)Advanced StrataFrame User (536 reputation)Advanced StrataFrame User (536 reputation)Advanced StrataFrame User (536 reputation)Advanced StrataFrame User (536 reputation)Advanced StrataFrame User (536 reputation)
Group: StrataFrame Users
Posts: 144, Visits: 618
Hi Greg,

thanks a lot for your help. After playing around a bit i found the reason why the function does not work as I expected it. I call it the "Cut and Paste Disease" because I copied the example but did not change

 loCommand.Parameters.Add("@pAdresse", SqlDbType.VarChar)

to

loCommand.Parameters.Add("@pAdresse", SqlDbType.Char)

Because my datatype is char.

Nowe everything works fine. But after all I have a more generic question and that is what I should do when my data-conversion has to become more precise (By now I used Les Pinters conversion tool to ha a starting point)? Shoul I use char or varchar types. Space is today no problem but speed will always be, so after my reading by now I decided to use the char-type. What is your suggestion?

Thanks a lot

 

Thomas

 


Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I tend to almost always use varchar (or nvarchar if I expect to support multiple languages). If I did use a char is would be in cases were all data would be close to or exactly the length of the field. It is my understanding that if the values are variable, then a Varchar is faster (because exactly the data that is needed is sent over the wire). Usually if I want to encode data, I use an enum and store an int in the database, which is way faster than a char.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search