Ado.Net Application

By
Hi Friends ! Today i am going to make a ado.net Application in .NET.In this application if you select one value from comboBox then  all values related to that id will display on the textBox  Fields.This is very useful concept for you ,if  you want to make any Application in  .NET.If you understand this concept then you will relate any problem with this concept when you are making any .NET Application.You can solve big problem very easily.Because all big problem are collection of  some small problems.
If you will follow these steps which is given below then you will become good application Developer in.NET  after few month.You can download whole application from bottom.
Step 1  First open Your MSSql Server->create a student table which has three Fields and insert some values which is given below in image:-

  • sid
  • name
  • age 

Step 2 Now open your visual studio->File->New->project->Windows Form Application->OK->Now make a Form like which is given below:-
In this form i have added some controls:
  • 1 ComboBox
  • 2 textBox
  • 4 lebel


Step 3 Now go the property of comboBox->Click Items->write  all Sid of database here.
see it;

Step 4 Now Double click on comboBox ->write the following code which is give below->replace existing Ado.net_application namespace with your namespace  if you are creating  a new application otherwise it will error.


using System;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;

namespace ado.net_application
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("Data source=RAMASHANKER-PC; integrated Security=yes; Database=master");
            con.Open();
            SqlCommand cmd = new SqlCommand("select name,age from student where sid="+comboBox1.SelectedItem.ToString(),con);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                textBox1.Text = dr[0].ToString();
                textBox2.Text = dr[1].ToString();
            }
            con.Close();
        }
    }
}

Note:- 
  1. If you import this application after download then need for replace namespace.
  2. Here i have used connected architecture for Database connectivity.Please keep attention on some points which is given below:
  • Write Data source correct[EX. Data source = Server name(ms sql server name)].
  • Write your Database name correct(By default it is master).
Step 5 Now Run the Application(press F5).
see it:


Note :- When you will change sid then name and age will change automatically.
For More:-

  1. Take Print receipt in Windows Form Application
  2.  Make Custom Registration and Login page With Ajax in ASP.NET
  3.  Host ASP.NET Application on Server Free
  4.  Host Asp.Net Application on IIS Server
  5. oops concepts

I Hope this is helpful for you.
To Get the Latest  Free Updates Subscribe
Click below for download application
        Download

2 comments:

  1. How to populate dropdownlist from database when form is loaded dynamically instead of adding iteams in it.

    ReplyDelete

Powered by Blogger.