473,382 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

DB Nulls & DataBinding!

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
Dec 19 '05 #1
2 1018
This is my attempt so far!
txtFirstName.Text = IIf(rdrSupervisorDetails("first_name") Is DBNull.Value,
String.Empty, rdrSupervisorDetails("first_name"))

"Adam Knight" <ad**@pertrain.com.au> wrote in message
news:e3**************@TK2MSFTNGP09.phx.gbl...
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

Dec 19 '05 #2
Adam,

Yeah, DBNull.Value is the way that I do it as well. Seems to work fine!

J

"Adam Knight" <ad**@pertrain.com.au> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
This is my attempt so far!
txtFirstName.Text = IIf(rdrSupervisorDetails("first_name") Is
DBNull.Value, String.Empty, rdrSupervisorDetails("first_name"))

"Adam Knight" <ad**@pertrain.com.au> wrote in message
news:e3**************@TK2MSFTNGP09.phx.gbl...
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


Dec 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Richard | last post by:
Hi, I'm having issues with DataBinding. I have a Form with two data bound comboboxes on it. When you select something in one combobox I may {or may not} want to change the selected item in the...
6
by: eye5600 | last post by:
Is there a cure for the problems using databinding with a DateTimePicker? I find that a) sometimes it works, sometimes it doesn't, and b) it fails silently causing all databinding on the DataSet...
1
by: Vik | last post by:
Concatenation operator & used in the databinding expressions for the datagrid template columns appears as '&amp;' in HTML. It causes an error when opening the pages. I have to replace '&amp;' by '&' each...
2
by: Mr Newbie | last post by:
Ive got the basic idea behind DataBinding Expressions, but I have a couple of questions, Ok its four actually :) Q1.) It would appear that if you use Page.DataBind that all child controls and...
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
2
by: Agnes | last post by:
Now, I understand my problem (bugs?) about the Tab Control & dataBinding 1)a simple blank form with tabcontrol , there are 2 pages, pages1 got 3 textboxes (txtShipperNAme,txtJobNo,txtVslName) and...
2
by: Kalpesh | last post by:
Hello, I am facing a design problem here & need your expert design advice on this. Scenario: I have a class called Vendor - which has several simple attributes like Name, Address etc Now,...
4
by: Arpan | last post by:
The following code works fine: <script runat="server"> Dim strName As String = "Arpan" Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) Page.DataBind() End Sub </script> <form...
0
by: =?Utf-8?B?cGhpbGptY2c=?= | last post by:
I've seen this question asked 100 times, but with no reasonable answer, other than to extend a control etc. Sorry if I'm going over old ground. I've a DropDownList inside a FormView control,...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.