473,799 Members | 2,985 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting data in dynamic controls through msaccess database

8 New Member
hi,
i am creating a form in my application which dynamically creates controls by getting information from a table in ms access database .now i would like it to get the text by using another table .
my code:
Expand|Select|Wrap|Line Numbers
  1.  Private Sub frmDataEntry_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.  
  3.         Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" & Application.StartupPath & "\customer.mdb")
  4.         Dim cn1 As New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=" & Application.StartupPath & "\customer.mdb")
  5.         Dim cmd As OleDbCommand
  6.         Dim dr As OleDbDataReader
  7.         Dim str As String
  8.         Dim txtBox As TextBox
  9.         Dim labl As Label
  10.         Dim pt As Point
  11.         Dim pt1 As Point
  12.         Dim cnt As Integer
  13.         Dim cnt1 As Integer
  14.         Dim siz As Size = New Size(200, 20)
  15.         Dim i As Integer
  16.         Dim ds As DataSet
  17.         Dim pbndTemp As Binding
  18.  
  19.         Try
  20.             If cn.State = ConnectionState.Closed Then
  21.                 cn.Open()
  22.             End If
  23.  
  24.             Dim ad As New OleDbDataAdapter("SELECT FldAn FROM tblCustomFieldAnswers WHERE AcctNum='" & m_stracctnum1 & "' And CustID = " & m_intcustnum1 & "", cn)
  25.             ds = New DataSet
  26.             ad.Fill(ds, "tblCustomFieldAnswers")
  27.  
  28.             str = "SELECT FieldName FROM tblCustomFields WHERE AcctNum='" & m_stracctnum1 & "'And CustID = " & m_intcustnum1 & ""
  29.             cmd = New OleDbCommand(str, cn)
  30.             dr = cmd.ExecuteReader
  31.  
  32.             While dr.Read
  33.  
  34.                 pt = New Point(140, cnt + 10)
  35.                 pt1 = New Point(10, cnt1 + 10)
  36.                 txtBox = New TextBox
  37.                 txtBox.Location = pt
  38.                 txtBox.Size = siz
  39.                 Me.Controls.Add(txtBox)
  40.  
  41.                 pbndTemp = New Binding("text", ds, "tblCustomFieldAnswers.FldAn")
  42.                 txtBox.DataBindings.Add(pbndTemp)
  43.  
  44.                 labl = New Label
  45.                 labl.Text = dr(i)
  46.                 labl.Location = pt1
  47.                 labl.Size = siz
  48.                 Me.Controls.Add(labl)
  49.  
  50.                 cnt = cnt + (txtBox.Height + 15)
  51.                 cnt1 = cnt1 + (txtBox.Height + 15)
  52.  
  53.             End While
  54.  
  55.         Catch ex As OleDbException
  56.  
  57.             MessageBox.Show(ex.ToString())
  58.  
  59.         End Try
  60.         If cn.State <> ConnectionState.Closed Then
  61.             cn.Close()
  62.         End If
  63.  
  64.     End Sub
iam able to get text in the controls but it only reads one row and shows the same data in all the controls.
how should i loop it so that it reads throught the entire table and displays data from all the rows into the controls?
Sep 19 '06 #1
2 1863
lanmou
8 New Member
hi,
i tried doing this. but now it only displays the data in the last control but all other controls are empty.can anyone help?

Expand|Select|Wrap|Line Numbers
  1. While dr.Read
  2.  
  3.                 pt1 = New Point(10, cnt1 + 10)
  4.  
  5.                 labl = New Label
  6.                 labl.Text = dr(i) & ":"
  7.                 labl.TextAlign = ContentAlignment.MiddleRight
  8.                 labl.Location = pt1
  9.                 labl.Size = lablsiz
  10.                 Me.Controls.Add(labl)
  11.  
  12.                 pt = New Point(175, cnt + 10)
  13.                 txtBox = New TextBox
  14.                 txtBox.Location = pt
  15.                 txtBox.Size = txtsiz
  16.                 Me.Controls.Add(txtBox)
  17.  
  18.                 cnt1 = cnt1 + (labl.Height + 15)
  19.                 cnt = cnt + (txtBox.Height + 15)
  20.             End While
  21.  
  22.             '-------------------------------
  23.             If cn1.State = ConnectionState.Closed Then
  24.                 cn1.Open()
  25.             End If
  26.  
  27.             str1 = "SELECT FldAn FROM tblCustomFieldAnswers WHERE AcctNum='" & m_stracctnum1 & "' And CustID = " & m_intcustnum1 & ""
  28.             cmd1 = New OleDbCommand(str1, cn1)
  29.             dr1 = cmd1.ExecuteReader
  30.  
  31.             While dr1.Read
  32.  
  33.  
  34.                 txtBox.Text = dr1(i)
  35.  
  36.             End While
Sep 20 '06 #2
lanmou
8 New Member
got it done.

Expand|Select|Wrap|Line Numbers
  1.  Try
  2.             If cn.State = ConnectionState.Closed Then
  3.                 cn.Open()
  4.             End If
  5.  
  6.             cn1.Open()
  7.             str1 = "SELECT FldAn FROM tblCustomFieldAnswers WHERE AcctNum='" & m_stracctnum1 & "' And CustID = " & m_intcustnum1 & ""
  8.             cmd1 = New OleDbCommand(str1, cn1)
  9.             dr1 = cmd1.ExecuteReader
  10.  
  11.  
  12.             str = "SELECT FieldName FROM tblCustomFields WHERE AcctNum='" & m_stracctnum1 & "'And CustID = " & m_intcustnum1 & ""
  13.             cmd = New OleDbCommand(str, cn)
  14.             dr = cmd.ExecuteReader
  15.  
  16.  
  17.             If dr1.HasRows = False Then
  18.  
  19.                 While dr.Read
  20.                     pt1 = New Point(10, cnt1 + 10)
  21.                     labl = New Label
  22.                     labl.Text = dr(i) & ":"
  23.                     labl.TextAlign = ContentAlignment.MiddleRight
  24.                     labl.Location = pt1
  25.                     labl.Size = lablsiz
  26.                     Me.Controls.Add(labl)
  27.                     pt = New Point(175, cnt + 10)
  28.                     txtBox = New TextBox
  29.                     txtBox.Location = pt
  30.                     txtBox.Size = txtsiz
  31.                     Me.Controls.Add(txtBox)
  32.  
  33.                     cnt = cnt + (txtBox.Height + 15)
  34.                     cnt1 = cnt1 + (labl.Height + 15)
  35.                 End While
  36.  
  37.             Else
  38.                 While dr.Read
  39.                     pt1 = New Point(10, cnt1 + 10)
  40.                     labl = New Label
  41.                     labl.Text = dr(i) & ":"
  42.                     labl.TextAlign = ContentAlignment.MiddleRight
  43.                     labl.Location = pt1
  44.                     labl.Size = lablsiz
  45.                     Me.Controls.Add(labl)
  46.                     While dr1.Read
  47.                         pt = New Point(175, cnt + 10)
  48.                         txtBox = New TextBox
  49.                         txtBox.Location = pt
  50.                         txtBox.Size = txtsiz
  51.                         Me.Controls.Add(txtBox)
  52.                         txtBox.Text = dr1(i)
  53.                         cnt = cnt + (txtBox.Height + 15)
  54.                     End While
  55.                     cnt1 = cnt1 + (labl.Height + 15)
  56.                 End While
  57.             End If
  58.  
  59.         Catch ex As OleDbException
  60.  
  61.             MessageBox.Show(ex.ToString())
  62.  
  63.         End Try
  64.         If cn.State <> ConnectionState.Closed Then
  65.             cn.Close()
  66.         End If
  67.         If cn1.State <> ConnectionState.Closed Then
  68.             cn1.Close()
  69.         End If
Sep 20 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
3536
by: Andrea M. Segovia | last post by:
Hello, I am a newbie to Oracle databases.... We have a visualization front-end tool connected to an Oracle back-end database on a Tru64 UNIX server. We also have clients with MS access databases who would like to share their data using this visualization tool but do not want to import their data into the Oracle server back-end.
5
8140
by: Mike Turco | last post by:
(This was also posted to comp.database.ms-access before I realized this was the hep group.) Lets say that my WinXP computer has two users: Michael and Kathryn. One or the other logs into the computer and opens up an Access database (I happen to be using 2002). There is no security on the database -- just click on the shortcut and you're in. I want to be able to determine who opened that database by knowing who logged into the computer.
9
2103
by: Tom Weston | last post by:
Help I have 4 databases containing different data relating to safety, not written by me. It is not possible to merge the databases into one large data base. I would like to create a user interface with 4 buttons, one for each database. The aim would be for the user to click on a button and the related database opens for use. When the database is closed the user interface with the buttons on returns. Can anybody offer a method of achieving...
1
1653
by: Kelly | last post by:
Hi Everyone I have a web application and all it basically does is ask for a user id and show a questionnaire. To create the questionnaire, I get the list of questions from the database and dynamically add controls (i.e,. labels, radiobuttons, textboxes) for each question. If the user has visited the page before, I will go to the database and populate the questionnaire with the answers that the user have entered before and display it to...
0
1178
by: Slam via DotNetMonster.com | last post by:
I want to create a couple of dynamic controls and the controls definitions are stored in a database. Once the the controls are created, I want to fill any dropdownlist with database values. And when a user selects or enter inputs from the dynamic controls those values will then be inserted into a database in comma delimited format. Then, when that user returns to view their selections I need those controls (textbox, dropdownlist, etc.)...
0
1345
by: pbb | last post by:
I have a web page on which I dynamically create controls based on the selection a user makes from a dropdownlist (this ddl is not dynamic). Depending on the user's selection, the controls could be any combination of textboxes, ddls, popup calendars, etc. The properties of the dynamic controls are stored in a SQL database so that my program can know what type of control to render and what items to put in the ddl etc. My problem is that I...
3
2143
by: Tim | last post by:
Hello All, Hope someone can point me in the right direction here. I have a ASPX page that is being created dynamically. My function adds Labels and Text Boxes to a Table ready for the user to fill them in. Once the user has entered their information I need to be able to store it all in a database. The only problem I have is that by using a Web Button all the dynamically created controls disapear beacuse of the postback. My
12
457
by: Hugh Welford | last post by:
hi Running an asp site on win/IIs/MSACCESS with a database reaching 45 meg. Responses seem a little slow. Could anyone provide a checklist of things to look at to optimise data access on this platform, or point me in the right direction where I can read up on the subject. Thanks Hugh
0
1356
by: srig | last post by:
hi all, i hav created a webpart for inserting a record in asp.net ,c# and deploy it in sharepoint.. my code is executing properly.. when i deploy it it asks for insert new record and wen i get the details and click insert the values are not getting stored in sql server database.. could any one point me out what s wrong in the program..i hav posted my prog below Thanks Sri using System; using System.Web.UI; using...
0
9686
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9540
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10475
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10250
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10026
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.