using ArrayList for Simple Scenario (Using C#)


I have 2 tables one has 6 textboxes, the other has 8 rows with one textbox per row.I need to insert into a table the values in the first 6 textboxesfrom table 1 plus value from textbox 1 row 1 to textbox 8 row 8 in table 2. altogether 8 insert queries, so I will need a for loopthat will attach the values form table 1 to each value in table 2 unless the value is null.can I create an array of texboxes in table 2 so then I could loop through the array?

Solution (Using C#):

//This code to implement
ArrayList list = new ArrayList();
list.Add(new Category("textbox1"),1);
list.Add(new Category("textbox2"),2);
list.Add(new Category("textbox3"),3);
list.Add(new Category("textbox4"),4);
list.Add(new Category("textbox5"),5);
list.Add(new Category("textbox6"),6);
list.Add(new Category("textbox7"),7);
list.Add(new Category("textbox8"),8);

foreach (Category cate in list)
sql = "INSERT INTO DB..tAble (col1, col2) VALUES ( ";
sql += "'" + cate.Type + "', " + "'" + cate.TypeCode + "');" ;
catch(Exception ex)

// add this class under same namespace
public class Category
public string Type;
public int TypeCode;

public Category()
public Category(string type, int tcode)
this.Type = type;
this.TypeCode = tcode;

protected void Insertdata(string sql)
// Your connection and query processing for database


Rahul said…

First of all. Thanks very much for your useful post.

I just came across your blog and wanted to drop you a note telling you how impressed I was with the information you have posted here.

Please let me introduce you some info related to this post and I hope that it is useful for .Net community.

There is a good C# resource site, Have alook


Popular posts from this blog

ASP.NET website "Cannot read configuration file due to insufficient permissions" in IIS 7 and Windows Server 2008

Error occurred in deployment step 'Install app for SharePoint': The System Account cannot perform this action.

Windows Server AppFabric: installation error , While installing SharePoint prerequisite installer