473,387 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

a check condition for my C# windows form application

i am new to C#. i need to create a windows form application for adding 5 student record using array... i have created it but i want to put a check condition for student id that is if it get repeted then a message should be displayed "student id all ready exist". but when i enter the detail of 1st student then that message is displayed....

here is the code that i have written:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using old_class_to_be_mod;
  10.  
  11. namespace WindowsFormsApplication1
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.        // int[] arr = new int[3];
  20.       // Student s = new Student();
  21.         Student[] s = new Student[5];
  22.  
  23.         private void Form1_Load(object sender, EventArgs e)
  24.         {
  25.             label1.Text = "Id";
  26.             label2.Text = "Name";
  27.             label4.Text = "Marks of Sub 1";
  28.             label5.Text = "Marks of Sub 2";
  29.             label6.Text = "Marks of Sub 3";
  30.             label7.Text = "Marks of Sub 4";
  31.             label8.Text = "percentage";
  32.  
  33.         }
  34.         int i = 0;
  35.         private void button1_Click(object sender, EventArgs e)
  36.         {
  37.  
  38.  
  39.             s[i] = new Student();
  40.             s[i].ID = int.Parse(textBox1.Text);
  41.             s[i].Name = textBox2.Text;
  42.             s[i].SEM = int.Parse(textBox3.Text);
  43.             s[i].get_marks(double.Parse(textBox4.Text), double.Parse(textBox5.Text),
  44.                 double.Parse(textBox6.Text), double.Parse(textBox7.Text));
  45.             textBox8.Text = s[i].ret_per().ToString();
  46.             if (check() == false)
  47.             { MessageBox.Show("User allready Exist"); }
  48.             i++;
  49.  
  50.         }
  51.  
  52.         bool check()
  53.         {
  54.             for (i = 0; i < s.Length; i++)
  55.             {
  56.                 if(s[i].ID==int.Parse(textBox1.Text))
  57.                 {return false;
  58.                 break;}
  59.  
  60.  
  61.                 }
  62.             return true;
  63.         }
  64.         private void button2_Click(object sender, EventArgs e)
  65.         {
  66.             for (i = 0; i < s.Length; i++)
  67.             {
  68.                 richTextBox1.Text += s[i].Name +"->" + s[i].ret_per().ToString()+"\n";
  69.             }
  70.         }
  71.     }
  72. }
Dec 25 '13 #1
1 2122
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code or formatted data.

The problem is that you're checking the student against itself. You need to check first before creating the student.
Dec 26 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: David | last post by:
So I'm a new user to Visual Studio .NET. I'm having a problem with an initial setup of a Windows Form Application for a Visual C++ Project. The Windows Form Application (.NET) template is not...
0
by: forge | last post by:
Installing Merge Modules from C# Windows Form Application (not using a setup and deployment project) Hi, Currently, we have an InstallShield project that creates a setup.exe that only...
1
by: Dean R. Henderson | last post by:
I have a Windows library that I bind into a Windows Form application and into an ASP.NET Web Application. I have a procedure in the library that executes a DTS Package. I have also used...
4
by: bob lambert | last post by:
Help I am trying to deploy to another pc a vb.net std 2002 windows form application. I am confused. I created a project - windows form I built form, compiled and debugged. I created a...
4
by: Dennis C. Drumm | last post by:
I've noticed that using Console.WriteLine statements to debug a Windows Forms Application will sometimes write output to the VS 2005 Output window and sometimes it doesn't. I know that...
3
by: Henry Seymour | last post by:
I've developed a .Net Windows Form application and used the Click-Once Deployment. In that application I would like to allow the user a click-once method of uninstalling it. I do not find an...
1
by: Dave | last post by:
Hello all, I have an application that is accessing files from a mapped drive. I have full access to the share that is mapped and from explorer can delete files as I need. My application needs to...
0
by: querry | last post by:
Hi all, I am developing a Windows form Application in VC++.NET using the Visual Studio 2005 installed on Windows Server 2003. The UI part of the project is almost complete. I am now looking forward...
2
by: ashkan0021 | last post by:
hi, i have a solution in C#.Net that includes 2 project and ASP.net & A Windows form application project, i want to open some pages of my asp.net project in my windows application, i'd be realy...
5
by: kirtisapra | last post by:
how to check existence of value in database to be inserted in text box before insertion in asp.net c# windows form application?
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.