What does IsDBNull(int) method do?

129
September 07, 2018, at 1:30 PM

I have many users in a MySQL table in a WinForms app. The user enters their username and password. My question is how can I check if there is a user with that username and password in the table in the database? Can I accomplish this with the IsDBNull() method? I asked in other sites on the following link:
link , but could not get an adequate answer there. Thanks in advance!

Answer 1

IsDBNull(int) method checks if a specific index you are reading from the database is null.

For example if your query was:

select 1,null;

IsDBNull(0) would have returned false (since the first field is 1) while IsDBNull(1) would have returned true (since it returns a NULL).

Note: It's also best practice to use this as a safety check before reading values from nullable columns.

Answer 2

Answering the question as asked...

I'm assuming you mean a MySQL version of SqlDataReader.IsDBNull(Int32) (IsDbNull(int) docs). It does what those docs say.

If you are reading a record from a data reader (something that implements IDataReader) you can test if a particular field (/column) value is NULL by using 'IsDbNull(zeroIndexedColumnNumber)`

It's not much use for checking "that [the] username and password [are] in the table in the database". For that, use the suggestion from @TimSchemlter:

SELECT 1 FROM TblUser WHERE Username=@username AND Password=@password. 

Then use MySqlCommand.ExecuteReader and check it's HasRows property

Rent Charter Buses Company
READ ALSO
MySQl query term abbreviation

MySQl query term abbreviation

I want to collect two different tablodas from different valuesThis process takes too long because the number of records is too large How can I speed up the query?

128
Queries in query set group in to one query using Django

Queries in query set group in to one query using Django

I have a query set like the below

146
The first html row is not being displayed (PHP & MYSQL)

The first html row is not being displayed (PHP & MYSQL)

So, let’s say I have 10 rows in my databaseHowever, after the mysql query, only 9 rows are being displayed in the html table

110