windows form

Hi Guys ,

I created windows form with datagridview and get entity of one table from my SQL server.

what I'm tying to do is to insert data to the database and show it in gridview (what I'm successful to do) but I have issue with validation after I implemented validation on the entity class t_test1:

here is my entity class which come from the database:

using System.ComponentModel.DataAnnotations;
using System.Globalization;

namespace WindowsFormsApplication1
    using System;
    using System.Collections.Generic;

    public partial class t_test1
        public int Id { get; set; }
        public string Name { get; set; }
        public string Lname { get; set; }
        [StringLength(5, MinimumLength = 10, ErrorMessage = "Name should not be longer than 5 characters.")]
        public string Address { get; set; }
        public string Phone { get; set; }
        public Nullable<decimal> Salary { get; set; }
        public Nullable<decimal> Bonus { get; set; }
        public Nullable<decimal> Total { get; set; }

Open in new window

This is my code:

namespace WindowsFormsApplication1
    public partial class Form1 : Form
        public Form1()

        private void btnAdd_Click(object sender, EventArgs e)
           DataTestEntities db = new DataTestEntities();
           t_test1 cust = new t_test1();

            cust.Name = txtname.Text;
            cust.Lname = txtlname.Text;
            cust.Address = txtaddr.Text;
            cust.Phone = txtphon.Text;
            cust.Salary = Convert.ToDecimal(txtsalar.Text);
            cust.Bonus = Convert.ToDecimal(txtbons.Text);
            cust.Total = cust.Salary + cust.Bonus;


        public void Filldg()
            DataTestEntities db = new DataTestEntities();
            dataGridView1.DataSource = db.t_test1.ToList();

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)


Open in new window

Moti Mashiah.NET DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems and Integration DeveloperCommented:
Hi Moti,

What issue specifically are you having with the validation?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Moti Mashiah.NET DeveloperAuthor Commented:
Hi Carl ,

Thank for your respod . I have solved the issue by putting the attribute [require]
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.