|
You may be right Dave it might be a bad idea from a security aspect but this code has to access two versions of a database one has four columns and the later has 5 columns. Since I don't know which it is going to be run on I have to use SELECT * in this instance.
Despite that, why does it return one value on XP and a different one on Vista?
|
|
|
|
|
maybe because it is accessing a different database?
are you using Visual Studio, have you declared the database to Visual, could it make a local copy and run your app on that one?
you can always list the field names instead of using a * in your SELECT statement; if the field does not exist, you'll get a clear error message. And whatever you do, if the field isn't there, you won't get its content.
|
|
|
|
|
Hi Luc, the problem here is that I don't want an error message, i.e. I don't want it to fail. It has to determine if the table has 4 or 5 columns and act accordingly. It is not a different database by the way. These are .sdf files and there is only one on the machine. I have got the user to check that.
|
|
|
|
|
TheComputerMan wrote: it might be a bad idea from a security aspect
No, it's a bad idea from an SQL standpoint. Your code can't tell which columns it's getting back until it examines the columns themselves. Right now, your code is ASSUMING it's getting back 5 columns when, in fact, it's only getting 4. There is no difference between the XP and Vista versions, other than your code is obviously hitting the wrong database.
If you change the schema of the database, you also change the number of columns you get back and also the order in which the columns arrive in your code. Since your code is assuming it's getting back certain columns in certain index positions, just making one change to the database may alter that order and totally screw up your code. You always specify the columns you want in the SQL and you access those columns in the returned dataset/reader/whatever with named indexes (using strings, not numbers) so you know your always getting the correct columns, no matter which order they get returned to you.
|
|
|
|
|
Actually Dave you are wrong. It is not hitting the wrong database because there is only one on the machine and that has 5 columns in the table. The reason the program has the facility to read a 4 column table is because there is another user out there that is using the 4 column version of the database table. As I stated originally it is not a problem of change in order the program cannot find the fifth column (4) - says it does not exist.
I am fully aware of how to access the columns using strings not numbers and normally do - that is not an issue here - but as you should be aware 'item' takes an integer argument. I will agree that the code is not ideal, but that does not detract from the fact that this is not the wrong database - it has 5 columns not 4, and it works on XP but not on Vista.
When it was transferred to XP on the machine in New Zealand it was exactly the same setup program that was used to install it on the Vista machine. Same code, same database, same everything.
I will however replace the integer values and send it out again to see if it works. I will let you know the result.
|
|
|
|
|
Since we can't see the code, we're just guessing.
There are other ways to do what you want in SQL without using "SELECT *". ID'ing the database before hand and having the data layer switch queries based on that would be a better route to go, though it adds complexity.
|
|
|
|
|
Hi Dave, I just finished re-writing the code to remove any 4 column support completely and using strings to access the columns as it should be and drawing down the column names rather than using *
It causes me a slight problem when going back a couple of rows but I have a work around now.
I shall send this out to New Zealand now and wait an see what the result is!
I will let you know - either way.
Thanks. David
|
|
|
|
|
I finally got a reply from New Zealand.
On his Vista machine he has .NET 2.0.50727.4016 and mine is .NET 2.0.50727.3053
He only has the one database, which is the new 5 column one and he has run the latest version of the code which has no SELECT * and all data row elements are explicitly referred to by name.
When it runs it just errors its way through the file so basically it is not seeing this 5th field. Would the difference in ,NET numbers be significant?
|
|
|
|
|
Nope. You've both got .NET 2.0 SP2.
The problem seems to be that you're assuming the database has this 5th column, when it doesn't. Or, the code is looking at a different database than you think it is.
|
|
|
|
|
Thanks Dave
Yes I am beginning to wonder. I have to go on what he tells me, but of course I cannot confirm. I will call this a day here as I am sure the problem lies with the user.
Many thank for your assistance.
|
|
|
|
|
Hi,
What do I need to do display on a form my
1..My default printer
2..List of all my printers
Basically what reference do I need to import to get my printer properties.
P.S. Any sample code would be greatly appreciated.
|
|
|
|
|
An explicit list of printers is available through PrinterSettings.InstalledPrinters
.NET has some classes that help you with most aspects of printing. One often only needs PrintDialog and PrintDocument. If that is not sufficient, get ready for quite some complexity (maybe caused by how it all grew over time.
|
|
|
|
|
See here[^].
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
|
|
|
|
|
|
Say goodbye to your spam post...
|
|
|
|
|
Voted to remove becouse advertising is not allowed in these forums.
|
|
|
|
|
You tell him, Tiger!
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC League Table Link
CCC Link[ ^]
|
|
|
|
|
|
ANd this has WHAT to do with VB.NET??
|
|
|
|
|
Hi,
How can I search for codes represent data type decimal(18,2)?
Have a code_textbox and search_button on a form.
have a query to seach code:
select * from commune_table
where (code=@code)
when I put value such as 2.02 no result yet the record is in the table correctly.
Thanks a lot!
|
|
|
|
|
You need to know that most real numbers (float, double) cannot be represented exactly using binary representations. So what is present in the database might well be 2.0199999976 which may be shown by some software as 2.02 but does not exactly equal 2.02
One way of getting around that problem is by not looking for an exact value, look for a range instead (say anything between 2.019 and 2.021). Another way, which I do not recommend, is by converting to string and chopping/rounding, then comparing.
|
|
|
|
|
Hi,
In the table code column shows values as 2.01,2.02 etc..
but if I pass a query for 2.01, I get no returned value.
again code data type as decimal(18,2)
thanks again..
|
|
|
|
|
and how do you pass your value (2.01 or 2.02) so that it ends up in @code?
is everything on its way a decimal, or are some non-exact floats/singles/doubles/reals used in the process?
|
|
|
|
|
Hi,
from a form in a textbox..you can simply in the value, it gets to table as you enter it
thanks
|
|
|
|
|
that is not answering my question.
without getting detailed answers or seeing all the relevant actual code I can't help you.
I repeat: reals/floats/singles/doubles anywhere in your path will cause inexact values in binary.
|
|
|
|