I assume you don't really want help. If you did, you'd tell us what line the error was on, what you did to try to fix it, etc.
wrote:System.Windows.Forms.DataGrid statedg5 = this.FindName("statedg5") ;
This returns an object. You need to cast it. Use this.FindName("statedg5") as DataGrid and THEN you need to check if the object is null, to make sure it was found OK.
wrote:String str = "insert into State(Code,Name)values ('" + this.txtstatecode.Text + "','" +
This is a nightmare. Apart from the obvious mess of writing SQL at random, if you give me access to this program in order to add a state, I can erase your database at will. You need to read up on parameterised queries and SQL injection.