Reputation: 83
( Visual Studio 2010 | Win7 Ultimate | C# )
How do I add a value to a table? I have a table called "suggestions" and I'm not sure how to add a value to it, remotely, not hardcoded in.
It's just simple tables, not sure what to call them.
string[] suggestions = new string[] { };
I want to add the textBox1.Text value to that table when a button is clicked.
(suggestions.add, couldn't find anything, the same with suggestions.insert)
Upvotes: 0
Views: 669
Reputation: 838
You can not change the size of an array; arrays always have a fixed length that is specified upon their creation.
In order to add or insert values to a list of strings (a table implies more than one dimension of data, correct?) use
List<String> suggestions = new List<String();
suggestions.Add("Value1");
You can also insert values into a specific position in the list using
suggestions.Insert(position, value);
Side note: The List class is really just a wrapper around an array that allows the array to grow in size. A raw array, however, can not increase in size after instantiation.
Upvotes: 1
Reputation: 4886
I assume that you have a database table stored in a database somewhere...
Assuming you are using SQL Server on your computer and that you have a database setup with a table called Answer and using C# with Linq 2 SQL as the ORM. Let's look at an example.
e.g
Some code to access your table is as follows
DataClasses1DataContext context = new DataClasses1DataContext(); Answer answer = new Answer(); answer.description = "Some Description"; context.Answers.InsertOnSubmit(answer); context.SubmitChanges();
I hope this helps.
Upvotes: 3
Reputation: 83719
try
List<string> suggestions = new List<string>();
suggestions.Add("Use Lists");
Upvotes: 4