DB Nulls & DataBinding!

  • Thread starter Thread starter Adam Knight
  • Start date Start date
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
 
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

Back
Top