P
P
Panicrust2014-05-23 15:06:54
SQL
Panicrust, 2014-05-23 15:06:54

How to write 1000 textbox values ​​to sql?

There are 1000 textboxes, possibly more. How to write their values ​​in this form? Needed for SQL query, which, by the way, is also gigantic..

...
cmd.Parameters.AddWithValue("@tb020a", tb020a.Text);
cmd.Parameters.AddWithValue("@tb020b", tb020b.Text);
cmd.Parameters.AddWithValue("@tb020c", tb020c.Text);
...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Smirnov, 2014-05-26
@Panicrust

Use a different data structure.
Two columns. The first one is the name (textBox.Name nvarchar(max)). The second is the content (textBox.Text ntext).
And insert the text line by line.
SQL server implementations have limits on the number of columns in a table. Even if the fields @tb020a and others are of type image, text, ntext (not physically stored in a table), you can still hit the limit (30,000 in SQL Server, according to technet.microsoft.com/en-us/library/ms143432.aspx ).
If the type is nvarchar(max), exhaustion will be faster, see msdn.microsoft.com/en-us/library/ms186981%28SQL.10... .

forearch(Control control in Controls)
{
    TextBox textBox = (TextBox)control;
    if(textBox != null)
    {
        ...
        cmd.Parameters.AddWithValue("@name", textBox.Name);
        cmd.Parameters.AddWithValue("@content", textBox.Text);
        ...
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question