how to create textboxes dynamically and insert textbox text
into sql database
Answers were Sorted based on User's Feedback
Answer / aravind
TextBox1 = new TextBox();
TextBox1.ID = "TextBox1";
TextBox1.Style["Position"] = "Absolute";
TextBox1.Style["Top"] = "25px";
TextBox1.Style["Left"] = "100px";
Form1.Controls.Add(TextBox1);
and using
insert into columuname value ("+ textbox1.text+")
Is This Answer Correct ? | 12 Yes | 9 No |
Answer / harsh
private void buttongenerate_Click(object sender, EventArgs
e)
{
int inputnumber = Int32.Parse
(TextboxInput.Text);
inputtextboxes = new List<TextBox>();
for (int i = 1; i <= inputnumber; i++)
{
Label labelinput = new Label();
TextBox textboxnewinpute = new TextBox();
labelinput.Text = "Input" + i;
labelinput.Location = new Point(30,
TextboxInput.Bottom + (i * 30));
labelinput.AutoSize = true;
textboxnewinpute.Text = "";
textboxnewinpute.Name = "MyTextbox";
textboxnewinpute.Location = new Point
(labelinput.Width, labelinput.Top - 3);
inputtextboxes.Add(textboxnewinpute);
this.Controls.Add(labelinput);
this.Controls.Add(textboxnewinpute);
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
foreach (Control ctrl in Controls)
{
if (ctrl.Name == "MyTextbox")
{
if (con != null)
{
using (con)
{
int a = Convert.ToInt32
(TextboxInput.Text);
for (int i = 1; i <= a; i++)
{
cmd = new SqlCommand
("insert into DynamicDBdemo values ('" + ctrl.Text + "')",
con);
cmd.CommandType =
System.Data.CommandType.Text;
if
(cmd.Connection.State == System.Data.ConnectionState.Closed)
{
cmd.Connection.Open
();
}
}
if
(cmd.Connection.State == ConnectionState.Open)
{
cmd.ExecuteNonQuery
();
MessageBox.Show
("data added successfully");
}
}
}
}
}
}
catch (SqlException sx)
{
MessageBox.Show(sx.Message);
}
finally
{
con.Close();
}
}
Is This Answer Correct ? | 3 Yes | 9 No |
How to convert any string to view state format in asp.net? §ÇÛ짬ªª³ö»Ç¾ö»ÂÇ¿¾»¼»¾ö¼ÉÇöÇÏǼ»Ãö®±ª§°ö«³ -- i want convert this string to view state.
what are the server controls used in sitepath navigation?
How do you do validations. Whether client-side or server-side validations are better ?
2 Answers InfoLinks, Microsoft,
What does this do? sn -t foo.dll
Name the two properties are on every validation control?
How to store a dataset in a viewstate?
what is asp and asp.net ?
2 Answers Inspira Technologies,
we are working in .net namespaces like using system.io,system.text. these namespace before we use "using " keyword what means of using?
7 Answers CEI, CSC, HCL, Tech Mahindra,
How many Directives r in ASP.NET?
What is the difference between application and cache variables?
What is HTTPContext and HTTPModule. What is the use of them?
how we deploy the asp.net 2.0 application