Ado.Net Application
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 will follow these steps which is given below then you will learn easily one of application in.NET
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:
· ComboBox
· textBox
· label/textbox
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=SHIVACHARAN-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:-
· 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.
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 will follow these steps which is given below then you will learn easily one of application in.NET
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:
· ComboBox
· textBox
· label/textbox
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=SHIVACHARAN-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:-
· 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.
No comments:
Post a Comment