Copying Access Database field to Textbox

Trying to copy database field to textbox without ussing databindings.

Page 1 of 1

0 Replies - 1527 Views - Last Post: 25 June 2009 - 12:18 AM Rate Topic: -----

#1 fichnick   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 24-June 09

Copying Access Database field to Textbox

Posted 25 June 2009 - 12:18 AM

Sorry if this question (and answer) have been posted before, but I've looked all over and cannot seem to find anything to help in this matter. I am new to 2008, although I've been using VB.Net for about 4 years or so at this point (always 2005). I remember being able to do this with 2005, but that method does not seem to work anymore...

Ok, so here is the deal. I am writing a program that has several textboxes (Date/Time, Building, Address, Apartment, Visitor, etc.) , a button, a datagrid view, 4 databases (Residents, BuildingInfo, Prohibited, and ResidentProhibited). What is supposed to happen is this: The forms loads, txtAPT has the focus, data is entered, and then focus is shifted to txtVisitor. When txtAPT looses focus, txtBuilding, and txtAddress are all supposed to be filled in with information from the appropriate database.

Essentially, txtBuilding and txtAddress are supposed to blank to begin with. txtAPT looses focus, the BuildingInfo database gets queried and returnes results similar to this: Count, Building, Address, Apartment. The query works perfectly fine and returns one result, however, I cannot figure out how to get the information in the Building and Address fields to copy to their respective locations.

Now, the reason I do not want to use DataBindings on the textboxes is this: There is another textbox for the Resident, and when the query runs may produce more than one resident for the returned apartment. DataBindings (as far as I know) only allow me to use the first (or last in some circumstances) name on the list. Currently, there are datagrids on the form but they will be invisible in the end. So without further delay, here is the code (most of which was not written by myself...)

Private Sub txtAPT_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles APTtxt.LostFocus
		Dim sql As String
		Dim sql2 As String
		Dim systemDate As Date
		Dim x As Integer
		Dim str As String = ""
		systemDate = Now
		If txtAPT.Text.Length <> 0 And cmbVisitor.Focus Then
			sql = "Select * from BuildingInfo where Apartment = '" & txtAPT.Text & "';"
			BuildingInfoda.Adapter.SelectCommand.CommandText = sql
			If Db1Ds.BuildingInfo.Count > 0 Then
				txtDate_Time.Text = systemDate.ToString
				txtBuilding.Text = Me.BuildingInfoda.Fill(BuildingInfoda.Components.Item("Building"))
				sql2 = "Select * from Resident where APT = '" & txtAPT.Text & "';"
				Residendda.Adapter.SelectCommand.CommandText = sql2
				If Db1Ds.Resident.Count = 0 Then
					MessageBox.Show("Our Records show this apartment is unoccupied." & ControlChars.CrLf & "Is there anyway you can contact the resident?", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
					txtAPT.Text = ""
				End If
			ElseIf Db1Ds.Resident.Count > 1 Then
				x = 0
				Do Until x >= Db1Ds.Resident.Count
					'str = 
					x += 1
				txtResident.Text = 
				'txtResident.Text = 
			End If
		End If
	End Sub

The problem I am having is occurring with this statement: txtBuilding.Text = Me.BuildingInfoda.Fill(BuildingInfoda.Components.Item("Building"))... Which is actually about the 100th or so rendition I have tried. Any help would be greatly appreciated.

This post has been edited by fichnick: 25 June 2009 - 12:21 AM

Is This A Good Question/Topic? 0
  • +

Page 1 of 1