Solved

windows form

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 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

11 Experts available now in Live!

Get 1:1 Help Now