Solved

windows form

Posted on 2014-11-09
1
80 Views
Last Modified: 2014-11-20
Hi guys ,

I build some create button in my windows form. I have two table connected with FK.

what I'm trying to do is to create and save that way:

 p.t_Note.Id = Convert.ToInt32(txtcnote.Text); // here is my issue when i'm trying to save to the FK Tb.

 private void btncreate_Click_1(object sender, EventArgs e)
        {

            if (txtdesc.Text != "" && txtserv.Text != "" && txtuser.Text != "" && txtpass.Text != "")
            {
                PasssaveEntities _db = new PasssaveEntities();
                t_password p = new t_password();
                p.Description = txtdesc.Text;
                p.Service = txtserv.Text;
                p.UserName1 = txtuser.Text;
                p.Passwd1 = txtpass.Text;
                p.t_Note.Id = Convert.ToInt32(txtcnote.Text); // here is my issue when i'm trying to save to the FK Tb.
                p.Created = DateTime.Today.Date;
                _db.t_password.Add(p);
                _db.SaveChanges();

                MessageBox.Show("Created successfuly");
                FillGrid();
                txtdesc.Clear();
                txtpass.Clear();
                txtserv.Clear();
                txtuser.Clear();
                txtcnote.Clear();

            }
            else
            {
                MessageBox.Show("You missed some value!");
            }

        }

Open in new window

0
Comment
Question by:Moti Mashiah
1 Comment
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 40431430
If the value in 'txtcnote.Text' is not a valid integer (or blank) then you'll get an exception.  You can wrap that whole section of code in a try/catch block, or possibly use Int32.TryParse() to see if the input is valid:
http://msdn.microsoft.com/en-us/library/f02979c7(v=vs.110).aspx

If that doesn't help, then please give more details about the error you're getting...
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question