Solved

save values of dynamic controls in sql db

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
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.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

813 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