MCQs Test!! VB Basic Test !! Essentials of VB !! Creating User Services !! function !! Anatomy !! GK March-2019 !! DATA TYPES IN JAVA !! Classes ,Constructor ,Methods,Inheritance !! Ecology-I !! Biology 2019 !! Gk april 2019 !! Biology (living world) !! Plant anatomy !! CELL STRUCTURES AND FUNCTION !! General biology !! Human physiology !! Data structure !! Ecology-II !! GK TEST !! Reproduction in plants !! Human reproduction !! The ABC of C !! Operating system set1 !! Operating system set2 !! Gk and current affairs !! Animal kingdom !! Number system !! Animal kingdom-II !! Gk TEST-III !! Number series !! Microorganisms !! Interview question in c !! Time and Work !! Percentage !! General history !! Average !! Cells !! Locomotion and Movement !! paging !! Bacteriology !! Page replacement policy !! Secondary memory and Disk scheduling !! Introduction of Nervous System and neurons !! Plant harmones !! Transport and Mineral Nutrition in Plants !! Neurotransmitters !! Modern Indian History !! Photosynthesis in Plants !! Modern Indian History-II !! Plant respiration !! Environment & Biodiversity !! Environment & Biodiversity - II !! Algae, Bryophytes, Pteridophytes !! Area !! Cricket !! Days of the Year (India and the World) !! Plant Pathology - I !! Indian Transport System !! Plant Pathology - II !! Aptitude !! Biology !! Botany !! C language !! Computer Science !! Core Java !! Gate !! GK !! Mysql !! Operating system !! Physics !! VB-Visual Basic !! Zoology

ADO.NET

ADO.NET Projects

ADO.NET Project 1

ADO.NET Examples

Examples

Display Data Using the DataGridview and Sqlconnection
Previous Home Next

Create a New Project in VS .NET

  1. Create a new project in VS .NET by choosing File, New, and then choosing the Project option.
  2. When the New Project dialog box appears, choose Visual C# Projects and Windows Applications. Name this project "Sqlconnection1". This creates a default form for you to start from.

ADD DATA SOURCE

Go to server Explorer and right click on data Connections and clik then Add Connectin and select data source ,server name and database name

then click the test connection. if text connection is succeeded click the ok button otherwise again try to connect to database.

Adding the Button and DataGrid Controls

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace using_oledbconn
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con =new SqlConnection
    ("Data Source=R4R-03\\SQLEXPRESS;Initial 
Catalog=student;Integrated Security=True");
con.Open();
SqlDataAdapter ad=new SqlDataAdapter
	("select * from student", con);
DataSet ds=new DataSet();
ad.Fill(ds,"student");
ds.GetXml();
dataGridView1.DataSource=ds.Tables[0];     
}       
}
}
Previous Home Next