assigning, declaring and accessing dynamic variable

M

mamun

Hi all,

I am trying to create variables dynamically. This is needed because
the user interface can have ten different textboxes with name as txt1,
txt2 and so on. I would like to get values of all and then run in
single transaction.

for (int i = 1; i <= 10; i++)
{
(qry + i)= "insert into table1(field1) values(value1)";
}

This portion of declaring variable (qry + i) is not right and how can
I assign the dynamic variable here.

after creating the query string I want to execute as:
try
{
for (int i = 1; i <= 10; i++)
{
if (qry+ i.ToString != null) //same problem here
{
(qry + i.ToString).ExecuteNonQuery(); //same
problem here
}
}
}

Could you please tell me how I can achive what I am trying to do?

I do highly appreciate your help.
thanks a ton in advance.
best regards,
mamun
 
B

Bruce Wood

Hi all,

I am trying to create variables dynamically. This is needed because
the user interface can have ten different textboxes with name as txt1,
txt2 and so on. I would like to get values of all and then run in
single transaction.

for (int i = 1; i <= 10; i++)
{
(qry + i)= "insert into table1(field1) values(value1)";
}

This portion of declaring variable (qry + i) is not right and how can
I assign the dynamic variable here.

after creating the query string I want to execute as:
try
{
for (int i = 1; i <= 10; i++)
{
if (qry+ i.ToString != null) //same problem here
{
(qry + i.ToString).ExecuteNonQuery(); //same
problem here
}
}
}

Could you please tell me how I can achive what I am trying to do?

I do highly appreciate your help.
thanks a ton in advance.
best regards,

You want to look into the subjects of arrays and collections.
 
M

mamun

Hi Bruce,

Thanks for the reply. Can I do it without array?

Do you have any samples which I can look?
Thanks again,

mamun
 
B

Bruce Wood

Hi Bruce,

Thanks for the reply. Can I do it without array?

Do you have any samples which I can look?

Why would you want to do it without using arrays? (Or, more properly,
collections in general, since an array is just one type of
collection.) An aggregate data structure (array or collection) is the
correct solution to the problem. Why make it hard on yourself?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top