Filter wrong database records in a DataGridView control (Visual Studio 2005)(Visual Basic) (Normalization)
I have this database and I need to load it with a visual basic form in Visual Studio 2005.
The database has 6 tables and they contain wrong data that I must filter when loading the database in the form.
A quick example:
First table is Category, which has 3 fields (id, name, description). In one record I have 2a for id (a numeric only field) and in other record I have m1lk for name (a string only field).
When I click a button I load the database into a DataGridView control. How do I stop visual basic from loading into the DataGridView control those records that have invalid data (like in my example).
I have try with SQL queries using WHERE and LIKE, like in
SELEC开发者_StackOverflow中文版T IdCategoría, NombreCategoría, Descripción
FROM Categorías
WHERE (NombreCategoría LIKE '[!l]%') AND (IdCategoría LIKE '[!abcdefghijklmnñopqrstuvwxyz]')
but it's really difficult to filter things like Angel* and P3ter and Hood8, all at the same time...
Please show me a example code in your answer so I can try it.
Thanks in advance.
If you define a column in an MS Access table using a numeric data type, it simply won't allow values like "2a". But text columns will allow values like "m1lk", because "m1lk" is a valid string.
Quick workaround
To select only those values that can be interpreted as numbers, use the isnumeric() function. You need a SQL statement along these lines.
SELECT your-column-list
FROM some-table
WHERE isnumeric(numeric-column-having-bad-data)
Be aware that expressions like isnumeric("2e5")
and isnumeric("2d5")
will return True. VBA interprets both "2d5" and "2e5" as 2^5 ("two to the fifth power").
To select data that contains no numerals at all, use a regular expression like this. (I'm not certain you're trying to do this.)
SELECT your-column-list
FROM some-table
WHERE some-column-name Not Like "*[0-9]*";
精彩评论