473,405 Members | 2,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,405 software developers and data experts.

How do I get data from SQL database to my dynamic textboxes VB.NET

Hello guys/girl, how are You. I have one problem. I'm creating a exam system which should give 40 random questions from database table(mySQL). I managed to create (not perfect, still small problems with .possition and .size ) textboxes and checkboxex ( on button click event ). And I managed to get ONE (first row) data from my sql but then it stops. I cannot create more textboxes or checkboxex. See my code below. If You didnt fully understand what I want or what I need, please ask question and I'll give the asnwer.

CODE IN COMMENT ( SPAM ERROR )
May 30 '17 #1
1 1328
Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.SqlClient
  2. Public Class Form1
  3.     Dim cn As New SqlConnection("Data Source=192.168.0.45,1433;Network Library=DBMSSOCN;Initial Catalog=DB_GS-TMT_SSuite;User ID=itmahir;Password=itadmin;")
  4.     Private m_textboxes() As TextBox = {}
  5.     Private m_checkboxes() As CheckBox = {}
  6.     Dim i As Integer = m_textboxes.Length
  7.     Dim a As Integer = m_checkboxes.Length
  8.     Public Overrides Property AutoScroll As Boolean
  9.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  10. *
  11.         ReDim Preserve m_textboxes(i)
  12.         m_textboxes(i) = New TextBox
  13.         With m_textboxes(i)
  14.             .Name = "TextBox" & i.ToString
  15.             .Text = "TextBox" & i.ToString
  16.             If m_textboxes.Length < 2 Then
  17.                 .SetBounds(10, 10, 100, 20)
  18.             Else
  19.                 .Left = m_textboxes(i - 1).Left
  20.                 .Top = m_textboxes(i - 1).Top + m_textboxes(i - 1).Height + 4
  21.                 .Size = m_textboxes(i - 1).Size
  22. *
  23.             End If
  24.             .Tag = i
  25. *
  26.         End With
  27.         AddHandler m_textboxes(i).TextChanged, AddressOf TextBox_TextChanged
  28.         Me.Controls.Add(m_textboxes(i))
  29.         CitacBaze()
  30.         ReDim Preserve m_checkboxes(a)
  31. *
  32.         m_checkboxes(a) = New CheckBox
  33.         With m_checkboxes(a)
  34.             .Name = "CheckBox" & a.ToString
  35.             .Text = "CheckBox" & a.ToString
  36.             If m_checkboxes.Length < 2 Then
  37.                 .SetBounds(135, 10, 100, 20)
  38.             Else
  39.                 .RightToLeft = m_checkboxes(a - 1).RightToLeft
  40.                 .Top = m_checkboxes(a - 1).Top + m_checkboxes(a - 1).Height + 4
  41.                 .Size = New Size(20, 20)
  42. *
  43.             End If
  44.             .Tag = a
  45.         End With
  46.         AddHandler m_checkboxes(a).CheckStateChanged, AddressOf CheckBox_CheckStateChanged
  47.         CitacOdgovora()
  48.         Me.Controls.Add(m_checkboxes(a))
  49. *
  50.     End Sub
  51.     Private Sub TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
  52.         Dim txt As TextBox = DirectCast(sender, TextBox)
  53.         Debug.WriteLine(txt.Name & ": [" & txt.Text & "]")
  54.     End Sub
  55.     Private Sub CheckBox_CheckStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
  56.         Dim chB As CheckBox = DirectCast(sender, CheckBox)
  57.         Debug.WriteLine(chB.Name & ": [" & chB.Text & "]")
  58.     End Sub
  59.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  60. *
  61.         Me.AutoScroll = True
  62. *
  63.  
  64.     End Sub
  65.     Public Sub CitacBaze()
  66.         cn.Open()
  67.         Dim cmd As New SqlCommand
  68.         Dim dadapter As New SqlDataAdapter
  69.         Dim datardr As SqlDataReader
  70.         Dim strSql As String
  71. *
  72.         strSql = "SELECT * FROM TBL_Testiranje_Radnik"
  73.         cmd.CommandText = strSql
  74.         cmd.Connection = cn
  75.         dadapter.SelectCommand = cmd
  76.         datardr = cmd.ExecuteReader
  77.         If datardr.HasRows Then
  78.             datardr.Read()
  79.             With m_textboxes(i)
  80.                 .Text = datardr("TekstPitanje")
  81. *
  82.             End With
  83. *
  84.         End If
  85.         cn.Close()
  86. *
  87.  
  88.     End Sub
  89.     Public Sub CitacOdgovora()
  90.         cn.Open()
  91.         Dim cmd As New SqlCommand
  92.         Dim dadapter As New SqlDataAdapter
  93.         Dim datardr As SqlDataReader
  94.         Dim strSql As String
  95. *
  96.         strSql = "SELECT * FROM TBL_Testiranje_Radnik"
  97.         cmd.CommandText = strSql
  98.         cmd.Connection = cn
  99.         dadapter.SelectCommand = cmd
  100.         datardr = cmd.ExecuteReader
  101.         If datardr.HasRows Then
  102.             datardr.Read()
  103. *
  104.  
  105.             With m_checkboxes(a)
  106.                 .Text = datardr("OdgovorA")
  107.             End With
  108. *
  109.         End If
  110.         cn.Close()
  111. *
  112.  
  113.     End Sub
  114.     Public Sub KreiranjeTextBox()
  115.         ReDim Preserve m_textboxes(i)
  116.         m_textboxes(i) = New TextBox
  117.         With m_textboxes(i)
  118.             .Name = "TextBox" & i.ToString
  119.             .Text = "TextBox" & i.ToString
  120.             If m_textboxes.Length < 2 Then
  121.                 .SetBounds(10, 10, 100, 20)
  122.             Else
  123.                 .Left = m_textboxes(i - 1).Left
  124.                 .Top = m_textboxes(i - 1).Top + m_textboxes(i - 1).Height + 4
  125.                 .Size = m_textboxes(i - 1).Size
  126. *
  127.             End If
  128.             .Tag = i
  129. *
  130.         End With
  131.         AddHandler m_textboxes(i).TextChanged, AddressOf TextBox_TextChanged
  132.         Me.Controls.Add(m_textboxes(i))
  133.         CitacBaze()
  134.     End Sub
  135.     Public Sub KreiranjeCheckBoxova()
  136.         ReDim Preserve m_checkboxes(a)
  137. *
  138.         m_checkboxes(a) = New CheckBox
  139.         With m_checkboxes(a)
  140.             .Name = "CheckBox" & a.ToString
  141.             .Text = "CheckBox" & a.ToString
  142.             If m_checkboxes.Length < 2 Then
  143.                 .SetBounds(135, 10, 100, 20)
  144.             Else
  145.                 .RightToLeft = m_checkboxes(a - 1).RightToLeft
  146.                 .Top = m_checkboxes(a - 1).Top + m_checkboxes(a - 1).Height + 4
  147.                 .Size = New Size(20, 20)
  148. *
  149.             End If
  150.             .Tag = a
  151.         End With
  152.         AddHandler m_checkboxes(a).CheckStateChanged, AddressOf CheckBox_CheckStateChanged
  153.         CitacOdgovora()
  154.         Me.Controls.Add(m_checkboxes(a))
  155. *
  156.     End Sub
  157. End Class
  158.  
May 30 '17 #2

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

Similar topics

1
by: Victor | last post by:
I have dynamically created n number of text boxes in a form like txtQL(1), txtQL(2) , ...txtQL(n) How can I retrieve the values in a loop? I'm confused as to how to approach this! Please help. ...
2
by: Jake_adl | last post by:
Is there any way to create a Microsoft.Practices.EnterpriseLibrary.Data.Database object without reading from a configuration file? I am writing a utility that manages databases in SQL Server....
1
by: Brian Pittman | last post by:
Hi, How do you go about obtaining the text typed in a dynamic textbox when the submit button is clicked. Thanks Brian 'Add textbox to controls collection Dim txtTextBox as TextBox = New...
3
by: Schapopa | last post by:
Hello, I have form where I want to display data from one record. So I created stored procedure with parameter and I populated some dropdown boxes with data, and now I would like to display that...
3
by: anniejacob | last post by:
hi, i would like to know how to bind my dynamic textboxes in C# to the database n get the value in my textboxes updated in my SQL database. if someone could help me soon.
3
by: sakhan | last post by:
Hello Friends, I want to create a row of 10 textboxes each time I click the add button. I want this to continue till it reaches five hundred I am using AJAX for this. It doesnot create 10...
0
by: manbassie | last post by:
I have xml web service which returns a dataset. I have textboxes which need to be populated with this data and my problem is how to bind the data to the textboxes when the form loads and be able to...
0
by: nitin24x | last post by:
hi, i need help ...ASp.net i created one form including some labels and text boxes for example firstname, Lastname,city,country,phone no. etc and textboxes for each. i have one database,in that...
2
by: englishman69 | last post by:
Hello, I have been banging my head against this one for a while... Searches online have revealed many different proposals for correcting my issue but none that I can follow! My basic situation...
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: 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...
0
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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
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,...

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.