Solved

windows form

Posted on 2014-11-09
1
81 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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 …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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