C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Application windows, menus & toolbars »

Dynamic controls through SQL Server using VB.Net


Posted Date: 02 Jul 2009    Resource Type: Code Snippets    Category: Application windows, menus & toolbars
Author: UltimateRenganMember Level: Diamond    
Rating: 1 out of 5Points: 4



You can create the Dynamic controls through SQL Server using VB.Net.
For Example
First you create the table createtextbox its have two field name label(nchar(10)),textbox(numeric(18, 0)).
You just drag and drop the Panel control from toolbox and place it on form.
Then you put the below code and excute it.

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Data.SqlClient
Public Class Form1
Dim con As SqlClient.SqlConnection
Dim cmd As SqlClient.SqlCommand
Dim rd As SqlClient.SqlDataReader
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con = New SqlClient.SqlConnection("Data Source=xxxxx;Initial Catalog=Emp;Integrated Security=True")
con.Open()
cmd = New SqlCommand("select label,textbox from createtextbox", con)
rd = cmd.ExecuteReader()

While (rd.Read())
Dim b As String
b = rd.Item("textbox").ToString
Dim y As Integer
y = Convert.ToInt32(b)
Dim i As Integer
For i = 1 To y
Dim l As New Label
l.Location = New Point(50, y)
y = y + 32
Panel1.Controls.Add(l)
'me.Controls.Add(l)


l.Text = rd.Item("label").ToString()
Dim x As Integer
Dim t As New TextBox
Dim j As Integer
x = Convert.ToInt32(b)
For j = 1 To x
t.Location = New Point(150, x)
x = x + 31
Panel1.Controls.Add(t)
'me.Controls.Add(t)
Next
Next
' rd.Close()
'con.Close()
End While


End Sub
End Class





Responses

Author: Rabiya    23 Jul 2009Member Level: Gold   Points : 1
Hi,

I tried this code. It is coming out of While (rd.Read()) loop. Please see the attachment.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Dynamic controls through SQL Server using VB.Net  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Create your own Input-box
Previous Resource: Generation of controls in Vb.net
Return to Discussion Resource Index
Post New Resource
Category: Application windows, menus & toolbars


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use