0% found this document useful (0 votes)
32 views

Programs

Uploaded by

Rupesh Phalne
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Programs

Uploaded by

Rupesh Phalne
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 15

Ado.

net

ado.net history

appliaction / different types


data :-databases,xml files,memeory ,text file,etc
data source :-location from where your data comes

data storage mechanism :-

temporary :-

permanat:- file storage mechnism :-1960-1970

file storage mechnism drawback

small amit of data


no security
data dupticar chance
data manipulation difficult

Ado.net :

_active x data object

it Is database technology of .net framwwwork /it is part of .net framework


it is data access technology
-------------------------------Connected architecture programs---------------------

)create windows form STEP 1

txtrn
txtname
txtage
txtcourse

btnclear
btnsave
btndelete
btnsearch
btnupdate

take 10 min create from


STEP 2 CREATE DATABASE TABLE AND PUT DATA IN THAT

how to start creating database


step 1:-create database first
step 2:-create database table in that
step 3:-put data

In this example my database name is "STUDENT" and


database table is "student_detail" which has four columns as "roll_no", "s_name", "age"
and "course".

Roll no is primary key

STEP 3
make connection string

you will get


then
click connect

you will get

all ready create database


now creat your own database

how right click on database folder in your server then add

click on new database it will take some time


database will get created
in hat add your table name

in that put some database

how to add tabel right click on database name then rigt click on tables folder then you will process
ahead
give name to your database
followo the rules while givivng databse name and table name ok

how to give table name


click ok done now put some data

refresjh your database form serverexplorer then see inside table foder category yiour table has created
done

put data now

right click on table

click
step 3 :- make connection string
how

steps
add your sqlserver here in visual studion server explorer window

how to that

from vie menu select server explorer


click sever explorer
then you will get this

now click database icon here


add your server name and
databas name
and then check weather you have got data or not ok

now add connection string in app.config folder


open app config file from solution explorer

add code in that

<?xml version="1.0" encoding="utf-8" ?>


<configuration>
<connectionStrings>

<add name="mydata" connectionString="Data Source=THN01-06\SQLEXPRESS;Initial


Catalog=College;Integrated Security=True"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>

now start writitng code in form .cs file for everything insert update delete serch,clear ok

used predefind classes give their ref also

using System.Data.SqlClient;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace adodemos
{
public partial class txtname : Form
{

SqlConnection conn;
SqlCommand comm;
SqlDataReader dreader;
string connstring = @"Data Source=THN01-06\SQLEXPRESS;Initial
Catalog=College;Integrated Security=True";

public txtname()
{

InitializeComponent();
}
//SEARCH CODE
private void btnsearch_Click(object sender, EventArgs e)
{
conn = new SqlConnection(connstring);
conn.Open();
comm = new SqlCommand("select * from student_detail where roll_no = " + txtrn.Text
+ " ", conn);
try
{
dreader = comm.ExecuteReader();
if (dreader.Read())
{
textBox2.Text = dreader[1].ToString();
txtage.Text = dreader[2].ToString();
txtcourse.Text = dreader[3].ToString();
}
else
{
MessageBox.Show(" No Record");
}
dreader.Close();
}
catch (Exception)
{
MessageBox.Show(" No Record");
}
finally
{
conn.Close();
}
}

private void btndelete_Click(object sender, EventArgs e)


{
conn = new SqlConnection(connstring);
conn.Open();
comm = new SqlCommand("delete from student_detail where roll_no = " + txtrn.Text +
" ", conn);
try
{
comm.ExecuteNonQuery();
MessageBox.Show("Deleted...");
txtage.Clear();
txtcourse.Clear();
textBox2.Clear();
txtrn.Clear();
txtrn.Focus();
}
catch (Exception x)
{
MessageBox.Show(" Not Deleted" + x.Message);
}
finally
{
conn.Close();
}
}
//UPDATE BUTTON CODE
private void btnupdate_Click(object sender, EventArgs e)
{
conn = new SqlConnection(connstring);
conn.Open();
comm = new SqlCommand("update student_detail set s_name= '" + textBox2.Text + "',
age= " + txtage.Text + " , course=' " + txtcourse.Text + "' where roll_no = "+txtrn.Text+" ",
conn);
try
{
comm.ExecuteNonQuery();
MessageBox.Show("Updated..");
}
catch (Exception)
{
MessageBox.Show(" Not Updated");
}
finally
{
conn.Close();
}
}

private void Form1_Load(object sender, EventArgs e)


{
txtrn.Focus();
}

//insert button code


private void button1_Click(object sender, EventArgs e)
{
conn = new SqlConnection(connstring);
conn.Open();
comm = new SqlCommand("insert into student_detail values(" + txtrn.Text + ",'" +
textBox2 .Text+ "'," + txtage.Text + ",'" + txtcourse.Text + "')", conn);
try
{
comm.ExecuteNonQuery();
MessageBox.Show("Saved...");
}
catch (Exception)
{
MessageBox.Show("Not Saved");
}
finally
{
conn.Close();
}
}

private void btnclear_Click(object sender, EventArgs e)


{
txtage.Clear();
txtcourse.Clear();
textBox2.Clear();
txtrn.Clear();
txtrn.Focus();
}
}
}

You might also like