?
Solved

save values of dynamic controls in sql db

Posted on 2011-02-11
2
Medium Priority
?
230 Views
Last Modified: 2012-05-11
i have created a form dynamically and trying to save the values into my database when user submit the form.

this code is for creating
 
row = New HtmlTableRow()
                    cell = New HtmlTableCell
                    Dim tb1 As New TextBox
                    tb1.ID = "TextBoxID" + (i).ToString
                    tb1.TextMode = TextBoxMode.MultiLine
                    tb1.Width = Unit.Pixel(350)
                    tb1.Height = Unit.Pixel(100)
                    cell.Controls.Add(tb1)
                    row.Controls.Add(cell)
                    newtables.Controls.Add(row)

Open in new window


this code is for saving
 
Dim dorkks = CType(newtables.FindControl("TextBoxID" + t.ToString), TextBox)
                Dim doconnstring As String = System.Configuration.ConfigurationManager.ConnectionStrings("dbconnector").ConnectionString
                Dim doSqlString As String = "INSERT INTO answer (qid, answer) VALUES ('" & cccdatareader.Item("qid") & "', '" & dorkks.ToString & "')"
                Dim doconn As OleDbConnection
                Dim docommand As OleDbCommand
                doconn = New OleDbConnection(doconnstring)
                docommand = New OleDbCommand()
                Dim dodatareader As OleDbDataReader
                doconn.Open()
                docommand.Connection = doconn
                docommand.CommandType = CommandType.Text
                docommand.CommandText = doSqlString
                dodatareader = docommand.ExecuteReader
                dodatareader.Close()
                doconn.Close()
                doconn = Nothing

Open in new window



when it save it doent save user inputed value. its saved as following
System.Web.UI.WebControls.TextBox

0
Comment
Question by:issay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
quizwedge earned 2000 total points
ID: 34877238
Try changing line 1 in the saving code from

Dim dorkks = CType(newtables.FindControl("TextBoxID" + t.ToString), TextBox)

To

Dim dorkks as Textbox = CType(newtables.FindControl("TextBoxID" + t.ToString), TextBox)

and line 3 in the saving code from

Dim doSqlString As String = "INSERT INTO answer (qid, answer) VALUES ('" & cccdatareader.Item("qid") & "', '" & dorkks.ToString & "')"

To


Dim doSqlString As String = "INSERT INTO answer (qid, answer) VALUES ('" & cccdatareader.Item("qid") & "', '" & dorkks.Text & "')"
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 34878222
looks like the default property is the control name rather than it "value"

dorkks.value.tostring?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question