hi
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 + ", ";
                        
                        break;
                    }
                }
            }
        
            database.UsersDataTable Tclients = database.Users;
            Tclients.AddUsersRow(a);
            usersTableAdapter.Update(Tclients);

the problem is with this code :

Tclients.AddUsersRow(a);

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

Thanks;

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

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"

thanks.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.