Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

windows form

Posted on 2014-11-09
1
Medium Priority
?
85 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 86

Accepted Solution

by:
Mike Tomlinson earned 1500 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

722 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