Click here to Skip to main content
15,899,126 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am created textbox dynamically . i want to upload datas from that textbox to db bt i wont works..

C#
TextBox t = new TextBox();
          t.Location = new System.Drawing.Point(379, 60);
          this.Controls["dynamicTextBox"].Text = "my text";
          t.Text = "What are you doing now";
          t.Multiline = true;
          t.Size = new System.Drawing.Size(430, 55);
          panel2.Controls.Add(t);


and one more thing i cannot able to ad t.id="dd"; id shows error. so i try t.name="dd" but insert db sqlcommand i cannot insert values "insert into tablename values '"+ dd.text+"'",c.
dd.text shows error.
kindly rectify or provide valid code
Posted

It doesn't matter if the text box is created dynamically or not. The basic principle is always the same:
- get the value from a control
- set the value into a parameter
- execute the parameterized statement.

In other words, you should use an SQL statement which uses parameters as explained in SqlParameter[^]
 
Share this answer
 
Comments
anandvijay1940 17-Aug-15 7:25am    
bt textbox t=new textbox();
t.id="sd";
id not works me..
i dont knw y?
Wendelius 18-Aug-15 0:22am    
At least two problems with the code above.
- What is bt?
- depending on the technology and what you have done, but most likely the textbox does not have a property called id.
Maciej Los 17-Aug-15 16:46pm    
5ed!
Wendelius 18-Aug-15 0:19am    
Thank you Maciej.
In addition to solution1 by Mika Wendelius[^], it's strongly recommended to read this article: Creating Dynamic Data Entry User Interfaces[^]

For further information, please see:
Create dynamic Textbox and Dropdownlist with Validation[^]
Save multiple Dynamic Textbox values to SQL database Windows Forms C#[^]
 
Share this answer
 
Comments
Wendelius 18-Aug-15 0:19am    
Good links!
Maciej Los 18-Aug-15 1:50am    
Thank you, Mika.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900