Solved

windows form

Posted on 2014-11-09
1
78 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# Json POSt to Rest API 4 31
ASP.NET 5 Templates 2 65
Need a starter for ETL protocol? 4 32
Web Form VB.Net  import CSV 4 17
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now