Solved

save values of dynamic controls in sql db

Posted on 2011-02-11
2
227 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 500 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

Industry Leaders: 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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

724 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