Solved

save values of dynamic controls in sql db

Posted on 2011-02-11
2
216 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
2 Comments
 
LVL 14

Accepted Solution

by:
quizwedge earned 500 total points
Comment Utility
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
Comment Utility
looks like the default property is the control name rather than it "value"

dorkks.value.tostring?
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now