DB Nulls & DataBinding!

A

Adam Knight

Hi all,

Just wondering how everybody goes about dealing with db nulls when binding
form controls to db data.
The code below produces an error if any column in the reader object contains
a db null value.

Is their a concise way of getting around this?

Cheers,
Adam

'fill reader object with command results
rdrSupervisorDetails = cmdGetSupervisorDetails.ExecuteReader()

'move to record returned in reader object
rdrSupervisorDetails.Read()

'populate form with values retrieve from db
txtFirstName.Text = CStr(rdrSupervisorDetails("first_name"))
txtLastName.Text = rdrSupervisorDetails("last_name")
txtDepartment.Text = rdrSupervisorDetails("department")
txtEmail.Text = rdrSupervisorDetails("email")
txtPhone.Text = rdrSupervisorDetails("phone")
txtMobile.Text = rdrSupervisorDetails("mobile")

'close & destroy db connection
Conn.Close()
Conn = Nothing
 
A

Adam Knight

This is my attempt so far!
txtFirstName.Text = IIf(rdrSupervisorDetails("first_name") Is DBNull.Value,
String.Empty, rdrSupervisorDetails("first_name"))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top