Stylesheet

Image
import * as React from 'react'; import styles from './Employeespotlight.module.scss'; import { IEmployeespotlightProps } from './IEmployeespotlightProps'; import { escape } from '@microsoft/sp-lodash-subset'; import * as $ from 'jquery'; import { WebPartContext } from '@microsoft/sp-webpart-base'; import { SPHttpClient, SPHttpClientResponse } from '@microsoft/sp-http'; import { SliderHelper } from './Helper'; export interface SpotlightDetails { userDisplayName: string; userEmail: string; userProfilePic: string; description: string; designation?: string; } export interface IStateEmployeeSlider { value:SpotlightDetails[]; } var result=[]; export interface ResponceDetails { title: string; id: string; } export default class Employeespotlight extends React.Component { private defaultProfileImageUrl: string = "/_layouts/15/userphoto.aspx?size=L"; private helper: SliderHelper = new SliderHe...

Windows Application CRUD Operation with ADO.net

 Posted by Ganesan - +919042710472  

Create STUDENTDB Database in Server Explorer.

Create table StudentDetails in STUDENTDB with the below code snippet,










Design Form1 as below,















Textbox Properties

StudentName Name - txtStudentName

Age Name - txtAge

Save -btnSave

Show Data Link Name -linkLabel1

Events

btnSave OnClick =btnSave_Click

Show Data Link onClick= linkLabel1_LinkClicked

Add below Namespace in Form1.cs

Using System.Data.SqlClient;

Using System.Configuration;


Add Reference System.Configuration.DLL in the Project.


In Form1.cs (Replace) put the below Snippet,

public partial class Form1 : Form
 {
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TestConnection"].ConnectionString); public Form1()
 {
 InitializeComponent();
 }
 private void btnSave_Click(object sender, EventArgs e)
 {
 con.Open();
 SqlCommand cmd = new SqlCommand("insert into StudentDetails values('"+txtStudentName.Tex+"'"+",'"+txtAge.Text+"')",con);
 int results=cmd.ExecuteNonQuery();
 con.Close();
 if (results > 0)
 {
 MessageBox.Show("Inserted Successfully");
 }
 }
 private void Clear()
 {
 txtStudentName.Text = string.Empty;
 txtAge.Text = string.Empty;
 }
 private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
 ShowData objShowData = new ShowData();
 objShowData.Show();
 this.Hide();
 }
 }

Add ShowData.cs form as below design,

Properties

DataGrid Name - dgvGridData

Update Data Name - lnkUpdate

 

Events

lnkUpdate Link  onClick Event - lnkUpdate_LinkClicked

ShowData Form OnLoad Event - ShowData_Load


Add below Namespace in ShowData.cs

Using System.Data.SqlClient;

Using System.Configuration;

In ShowData.cs (Replace) put the below Snippet,

public partial class ShowData : Form
{
 SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TestConnection"].ConnectionString); public ShowData()
 {
 InitializeComponent();
 }
 private void ShowData_Load(object sender, EventArgs e)
{
 SqlCommand cmd = new SqlCommand("select * from StudentDetails", con);
 SqlDataAdapter ada = new SqlDataAdapter(cmd);
 DataSet ds = new DataSet();
 ada.Fill(ds); dgvGridData.DataSource = ds.Tables[0];
 }
 private void lnkUpdate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
 UpdateUserData objUpdateUserData = new UpdateUserData();
 objUpdateUserData.Show();
 this.Hide();
 }
 }


Add UpdateUserData.cs Form as below Design,


















Properties

StudentId textbox Name - txtStudentId

StudentName Textbox  -txtStudentName

Age Textbox   - txtAge

Update button name -btnUpdate

Get Data button Name - btnGet

Clear button Name - btnClear

Show Data Link Name -linkLabel1

 

Event :

btnUpdate onClick =btnUpdate_Click

btnGet onClick= btnGet_Click

btnClear onClick =btnClear_Click

linkLabel1 onClick - linkLabel1_LinkClicked


Add below Namespace in UpdateUserData.cs

Using System.Data.SqlClient;
Using System.Configuration;

Put (Replace) the below snippet in UpdateUserData.cs ,

public partial class UpdateUserData : Form
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TestConnection"].ConnectionString);
 public UpdateUserData()
 {
 InitializeComponent();
 }
 private void btnUpdate_Click(object sender, EventArgs e)
 {
 con.Open();
 SqlCommand cmd = new SqlCommand("Update StudentDetails Set StudentName='" + txtStudentName.Text + "',Age='" + txtAge.Text + "' where StudentId=" + txtStudentId.Text, con);
 int results = cmd.ExecuteNonQuery();
 con.Close();
 if (results > 0)
 {
 MessageBox.Show("Updated Successfully");
 }
 Clear();
 }
 private void Clear()
{
 txtStudentId.Text = string.Empty;
 txtStudentName.Text = string.Empty;
 txtAge.Text = string.Empty;
 btnGet.Enabled = true;
 }
 private void btnGet_Click(object sender, EventArgs e)
 {
 con.Open();
 SqlCommand cmd = new SqlCommand("select * from StudentDetails where StudentId="+txtStudentId.Text, con);
 SqlDataReader dr = cmd.ExecuteReader();
 while (dr.Read())
 {
  txtStudentName.Text = dr["StudentName"].ToString();
  txtAge.Text = dr["Age"].ToString();
 }
 con.Close();
 btnGet.Enabled = false;
 }
 private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
 ShowData objShowData = new ShowData();
 objShowData.Show();
 this.Hide();
 }
 private void btnClear_Click(object sender, EventArgs e)
 {
 Clear();
 }
 }

The Output as below,






















Article by Maria Academy

Comments

Popular posts from this blog

Stylesheet