Sooo many problems in such a small amount of code. Where do I start? Well, why would you want to create two instances of the UserTbl class when you need to add just a single user?
First, your UserTbl class needs an overhaul. You're thinking in terms of tables when you should be thinking in terms of a single user. The class should describe a User record:
public partial class User
{
public int Id { get; set; }
public string Name { get; set; }
}
You'll have to update your Database2Entities1 class to change UserTbls to Users and use the User type instead of what you have now.
Next, you can have a class that manages the users, something like this:
public static class UserManager
{
public static void AddUser(User user)
{
using Database2Entities1 db = new();
db.Users.Add(user);
db.SaveChanges();
}
}
Now, when you want to add a user, you just do this:
private void btn_Click(object sender, RoutedEventArgs e)
{
User newUser = new()
{
Name = txtbox.Text
};
UserManager.Add(newUser);
}
Note: There are still plenty of problems with this code! First instance, you can add the same name to the Users table without any error at all! You're also not validating the content of the textbox before you use it.