|
-
Sep 24th, 2008, 08:32 PM
#1
Thread Starter
Hyperactive Member
How could I reduce this Code
vb Code:
Dim DRow As DataRow = DS.Tables(0).Rows(0)
If DS.Tables(0).Rows.Count > 0 Then
.txtCourseCode.Text = DRow.Item("CourseCode").ToString()
.txtRoomNumber.Text = DRow.Item("RoomNumber").ToString()
.txtSchoolYear.Text = DRow.Item("SchoolYear").ToString()
.txtTeacher.Text = DRow.Item("Teacher").ToString()
End If
Since theirs only 1 ROW in the Table, How could I just read from that instead of having the DataRow and so on? Is their a way to reduce / optimize it? I know its not a lot, but I don't want redundant code.
-
Sep 24th, 2008, 08:51 PM
#2
Re: How could I reduce this Code
There is no redundant code there. The only issue with that code is that you're getting the first DataRow before you actually check that there is a first DataRow to get. If you know for sure that there's one DataRow then what's the check for? If you don't know for sure that there's one DataRow then that first line's going to throw an exception if there isn't.
-
Sep 25th, 2008, 02:00 AM
#3
Re: How could I reduce this Code
Big long lists of filling Textboxes as other controls with database fields is common in VB.NET. There's nothing wrong with it.
If constructed correctly, you could databind those textboxes to your database though, but that has drawbacks along with the benefits it offers so you'd really have to determine if it's right for you and in the end, may be just as much work to set up.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|