473,513 Members | 2,401 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

updating data into the database from dynamically created controls..

8 New Member
hi,
Iam developing a application where a form displays dynamically created contols and displays data in it from the database.
this form allows the user to edit records and any changes made to it should be updated in to the database.
since the contols are dynamically created iam not able to figure out how to refer to them and save the changes.
can anyone guide me here please.i would really appreciate the help.
thanks.
Sep 20 '06 #1
1 1333
lanmou
8 New Member
well to be more clearer i would like to provide more information on my form.
this form is displaying only the text boxes right now.so all the input would have to be updated from these dynamic textboxes to the database.
this is my code in the forms load event:

visual basic 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 dr1 As OleDbDataReader 
  8.         Dim str As String 
  9.         Dim str1 As String 
  10.         Dim cmd1 As OleDbCommand 
  11.         Dim txtBox As TextBox 
  12.         Dim labl As Label 
  13.         Dim pt As Point 
  14.         Dim pt1 As Point 
  15.         Dim cnt As Integer 
  16.         Dim cnt1 As Integer 
  17.         Dim lablsiz As Size = New Size(150, 20) 
  18.         Dim txtsiz As Size = New Size(300, 20) 
  19.         Dim i As Integer 
  20.         Dim ds As DataSet 
  21.  
  22.         Try 
  23.             If cn.State = ConnectionState.Closed Then 
  24.                 cn.Open() 
  25.             End If 
  26.  
  27.             cn1.Open() 
  28.             str1 = "SELECT FldAn FROM tblCustomFieldAnswers WHERE AcctNum='" & m_stracctnum1 & "' And CustID = " & m_intcustnum1 & "" 
  29.             cmd1 = New OleDbCommand(str1, cn1) 
  30.             dr1 = cmd1.ExecuteReader 
  31.  
  32.  
  33.             str = "SELECT FieldName FROM tblCustomFields WHERE AcctNum='" & m_stracctnum1 & "'And CustID = " & m_intcustnum1 & "" 
  34.             cmd = New OleDbCommand(str, cn) 
  35.             dr = cmd.ExecuteReader 
  36.  
  37.  
  38.             If dr1.HasRows = False Then 
  39.  
  40.                 While dr.Read 
  41.                     pt1 = New Point(10, cnt1 + 10) 
  42.                     labl = New Label 
  43.                     labl.Text = dr(i) & ":" 
  44.                     labl.TextAlign = ContentAlignment.MiddleRight 
  45.                     labl.Location = pt1 
  46.                     labl.Size = lablsiz 
  47.                     Me.Controls.Add(labl) 
  48.                     pt = New Point(175, cnt + 10) 
  49.                     txtBox = New TextBox 
  50.                     txtBox.Location = pt 
  51.                     txtBox.Size = txtsiz 
  52.                     Me.Controls.Add(txtBox) 
  53.  
  54.                     cnt = cnt + (txtBox.Height + 15) 
  55.                     cnt1 = cnt1 + (labl.Height + 15) 
  56.                 End While 
  57.  
  58.             Else 
  59.                 While dr.Read 
  60.                     pt1 = New Point(10, cnt1 + 10) 
  61.                     labl = New Label 
  62.                     labl.Text = dr(i) & ":" 
  63.                     labl.TextAlign = ContentAlignment.MiddleRight 
  64.                     labl.Location = pt1 
  65.                     labl.Size = lablsiz 
  66.                     Me.Controls.Add(labl) 
  67.                     While dr1.Read 
  68.                         pt = New Point(175, cnt + 10) 
  69.                         txtBox = New TextBox 
  70.                         txtBox.Location = pt 
  71.                         txtBox.Size = txtsiz 
  72.                         Me.Controls.Add(txtBox) 
  73.                         txtBox.Text = dr1(i) 
  74.                         cnt = cnt + (txtBox.Height + 15) 
  75.                     End While 
  76.                     cnt1 = cnt1 + (labl.Height + 15) 
  77.                 End While 
  78.             End If 
  79.  
  80.         Catch ex As OleDbException 
  81.  
  82.             MessageBox.Show(ex.ToString()) 
  83.  
  84.         End Try 
  85.         If cn.State <> ConnectionState.Closed Then 
  86.             cn.Close() 
  87.         End If 
  88.         If cn1.State <> ConnectionState.Closed Then 
  89.             cn1.Close() 
  90.         End If 
  91.  
  92.     End Sub--------------------------------------------------------------------------------
so now when they make changes and hit the edit button the changes made to the text of any textboxes should be stored back to FldAn in customfieldanswers.
please help!!
thanks,
Sep 21 '06 #2

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

Similar topics

3
2460
by: Ryan.Chowdhury | last post by:
This is a general question regarding the use of view and stored procedures. I'm fairly new to databases and SQL. I've created a SQL database using an Access Data Project ("ADP") and I'm...
4
1995
by: Darrel | last post by:
I'm creating a table that contains multiple records pulled out of the database. I'm building the table myself and passing it to the page since the table needs to be fairly customized (ie, a...
3
1785
by: Jon Agiato | last post by:
Hi, I am trying to use a data grid in a web application in which I have three tiers. The DataGrid is not set up to a data source, or a data adapter, so everytime I make a change I send the cell...
5
2013
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
3
1979
by: Denise | last post by:
I am working with some pre-written code that dynamically builds a page with user controls based on data. I need to attach my Javascript to one of the controls on the form - I do not have access to...
1
4285
by: sekisho | last post by:
I'm dynamically adding a column of labels and a column of text boxes to a panel on a webform, based on data returned from an SQL query, which the user builds by selecting options from a few...
3
2135
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...
1
4872
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
2
5685
by: =?Utf-8?B?TUNN?= | last post by:
I have an asp.net page that contains an update panel. Within the update panel, controls get added dynamically. During partial page post backs the controls within the panel will change. I have a...
0
7166
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...
0
7386
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,...
0
7543
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...
0
7534
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...
0
5689
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5094
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3236
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...
0
1601
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 ...
0
459
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.