i write some code to write for access file (.db) but i have some problem and i dont know how to solve it...

Here is the code :

string a = "";
            foreach (Control c in this.Controls)
                for (int i = 1; i <= 80; i++)
                    if (c.Name == "textBox" + i.ToString())
                      //  c.Text = i.ToString();
                        a += c.Name + ", ";
            database.UsersDataTable Tclients = database.Users;

the problem is with this code :


i cant to put var instead textBox1.Text,TextBox2.Text .....
why?? and how can i do it??


The sentence Tclients.AddUsersRow(a); is expecting a to be a UserRow, not a string.

In order this to work you must:
1) change the line 2 to: var a = new UserRow;
2) change the line 11 to: a.Item(0) += c.Name + ", "; // because the index is base 0 and assuming you only need one field

Hope this helps

The result should

Edited 5 Years Ago by lolafuertes: n/a

thanks man but i have problem with this line :

var a = new UsersRow;

the eror is :

"Error 1 The type or namespace name 'UsersRow' could not be found (are you missing a using directive or an assembly reference?) "

"Error 2 A new expression requires (), [], or {} after type"


1. UserRow reference is not added to a project. If you created that class, add reference, or if that class is in .NET Framework Base Class Library add reference to it with 'using' directive.

2. After createing a new instance of any class in C# there must be () or [] or {}.

var a = new UsersRow();

Please, be so kind to confirm that a dataset deinition exists on your project and the 'database' is created from it.

If my assumption is OK, then you should have also table definitions for table Users as 'UsersDataTable? and definitions for 'UsersRow'.

If all this is ok, then changing the line 1 as proposed by jugosoft will be enough.

Hope this helps.

This article has been dead for over six months. Start a new discussion instead.