This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Me And My Respected Teacher Mr Kamal Sheel Mishra

Mr. K.S. Mishra is HOD of Computer Science from SMS Varanasi where I have completed my MCA

Me And My Respected Teacher Mr Udayan Maiti

Mr. Udayan Maiti is a senior .Net Expert and has guided many professionals of multi national Companies(MNC)

Me And My Best Friend Mr Ravinder Goel

Mr. Ravinder Goel is a senior Software Engineer and now he is working Wipro Technology

Friday, 10 October 2014

What is FileStream Class in C# and How to applied read/write Operation with its

What is FileStream and File Class in C# and How to applied read/write Operation with its......

FileStream can be used to perform the basic operations of reading and writing operating system files. To use this class, you must first declare a variable of the class FileStream.

Parameters:

  • Path:  A relative or absolute path for the file that the current FileStream object will encapsulate.
  • Mode: A constant that determines how to open or create the file.
  • Access: A constant that determines how the file can be accessed by the FileStreamobject. This gets the System.IO.FileStream.CanRead ,System.IO.FileStream.CanWrite properties of the FileStream object. System.IO.FileStream.CanSeek is true if path specifies a disk file.
Exceptions:

  1. System.ArgumentNullException:nd 
  2. System.ArgumentException:
  3. System.NotSupportedException:
  4. System.IO.FileNotFoundException:
  5. System.IO.IOException:
  6. System.Security.SecurityException:
  7. System.IO.PathTooLongException:
  8. System.ArgumentOutOfRangeException:
  9. System.UnauthorizedAccessException:
  10. System.IO.DirectoryNotFoundException:
  11. System.UnauthorizedAccessException:

Source Code:…………….

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 this  namespace
using System.IO;

namespace BasicwithFileHanding
{
public partial class FileStreamConcept : Form
{
public FileStreamConcept()
{
InitializeComponent();
}


string filepath, strcontent;

// code for how to create TextBox with Browse Concept with using openFileDialog1……………………

private void btnBrowse_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
txtselectedFile.Text = openFileDialog1.FileName;
filepath = txtselectedFile.Text;
}
}

//  create method for WriteFile………………………..

public void WriteFile(string FileName, string content)
{
FileStream fs = new FileStream(FileName, FileMode.Create, FileAccess.Write);
if (fs.CanWrite)
{
byte[] buffer = Encoding.ASCII.GetBytes(content);
fs.Write(buffer, 0, buffer.Length);
}
fs.Flush();
fs.Close();

}
string result;

//  create method for ReadFile…………………

public void ReadFile(string FileName)
{
FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);
if (fs.CanRead)
{
byte[] buffer = new byte[fs.Length];
int bytesread = fs.Read(buffer, 0, buffer.Length);
result = Encoding.ASCII.GetString(buffer, 0, bytesread);
}

fs.Close();
txtesult.Text = result;
}
// Write Button Click…………………

private void btnWrite_Click(object sender, EventArgs e)
{
strcontent = txtesult.Text;
WriteFile(filepath, strcontent);
MessageBox.Show("Write Successfully");

}
//Read Button Click…………………

private void btnRead_Click(object sender, EventArgs e)
{
ReadFile(filepath);
}
}
}

//Result…………………




Note : You can also do above  Concept with File.WriteAllText and File.ReadAllText  and we  will  also  use  openFileDialog1 and saveFileDialog1 in this  code



public static string[] ReadAllLines(string path, Encoding encoding);

Summary: Opens a text file, reads all lines of the file, and then closes the file.
Parameters:
Path: The file to open for reading.
Returns: A string containing all lines of the file.

public static void WriteAllLines(string path, string[] contents, Encoding encoding);

   
Summary: Creates a new file, writes the specified string to the file, and then closes the file. If the target file already exists, it is overwritten.
 Parameters:
        path: The file to write to.
        contents:The string to write to the file.

Source Code:…………….
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 this name  space
using System.IO;

namespace BasicwithFileHanding
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}


string filepath;
// code for how to create TextBox with Browse Concept with using openFileDialog1
private void btnBrowse_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
txtselectedFile.Text = openFileDialog1.FileName;
filepath =txtselectedFile.Text;
}
}
//code for Write
private void btnWrite_Click(object sender, EventArgs e)
{

if(saveFileDialog1.ShowDialog()==System.Windows.Forms.DialogResult.OK)
File.WriteAllText(filepath, txtesult.Text);
}
//code for Read
private void btnRead_Click(object sender, EventArgs e)
{
filepath =txtselectedFile.Text;
string result= File.ReadAllText(filepath);
txtesult.Text = result;

}
}
}

Result




Sunday, 5 October 2014

What is Indexes in Sql Server and Describe Clustered Index and NonClustered Index

What is Indexes in Sql Server

An index can be created in a table to increase the performance of application and we can get the data more quickly and efficiently. Suppose now we are reading book then I need to search each page of the book because I don’t know in which page that word information exists it’s time taken process. Instead of reading the each page of book to get that particular word information if I check the index of book (Glossary) it is much quicker for us to get the pages which contains the information with Index Page
This same logic applies for retrieving data from a database table. Without an SQL Index, the database system reads through the entire table to locate the desired information. If we set the proper index in place, the database system first go through the index to find out where to retrieve the data, and then go to that location directly to get the needed data. This is much faster due to the SQL Index. Creating and removing indexes on table will not show any affect on application because indexes operate behind the scenes.


For Example:

create table tbEmp(SrNo int,Name varchar(50),Salary int)
insert into tbEmp values(1,'Kafil Alam',90000)
insert into tbEmp values(3,'Shivak Sharma',15000)
insert into tbEmp values(5,'Anupam',12000)

select * from tbEmp
Create Index with Sql Query………………………….
-- query for create index
create index tb_name on tbEmp(Name asc)
-- To Check index
sp_helpindex tbEmp
--To drop index with table  name
drop index tbEmp.tb_name

select * from tbEmp

Note: By Default index is non-clustered index

Create Index with Sql Wizard ………………………….




Type of Indexes

  1. Clustered Index
  2. Non Clustered Index
  3. Unique
  4. Filtered
  5. XML
  6. Full text
  7. Spatial
  8. Column Store
  9. Index with includes columns
  10. Index with computed columns
What is Clustered Index A Clustered Index determine the physical order of data in a table for this reason a table can have only one clustered index

For Example:
create table tblstudent( RollNo int ,Name varchar(50),Gender varchar(50),Course varchar(50))

execute sp_helpindex tblstudent

Error is The object 'tblstudent' does not have any indexes, or you do not have permissions.
insert into tblstudent values (3,'Kush Tiwari','Male','Mca')
insert into tblstudent values (1,'Ravi Singh','Male','MTech')
insert into tblstudent values (5,'Himank Singh','Male','Bca')

select * from tblstudent

Result:

Note: when RollNo Column is maked as primary key ,P K Constraint create clustered index automatically if no clustered index already exists  the table
drop table tblstudent

create table tblstudent( RollNo int primary key ,Name varchar(50),Gender varchar(50),Course varchar(50))

insert into tblstudent values (3,'Kush Tiwari','Male','Mca')
insert into tblstudent values (1,'Ravi Singh','Male','MTech')
insert into tblstudent values (5,'Himank Singh','Male','Bca')

execute sp_helpindex tblstudent

select * from tblstudent

Result

Create a composite clustered index on the table Name and Gender columns...............
create clustered Index Ix_tblStudent_NameGender on tblstudent(Name asc,Gender desc)
when execute this query you can found this type error…….
Error Message   Msg 1902, Level 16, State 3, Line 1
Cannot create more than one clustered index on table 'tblstudent'. Drop the existing clustered index 'PK__tblstude__7886D5A024927208' before creating another.

Means you can not create more than one clustered index on table tbstudent

Then drop index with this line

drop index tblstudent.PK__tblstude__7886D5A01FCDBCEB

or  you can directly from sql  wizard …………………..
then again  executed this  query

create clustered Index Ix_tblStudent_NameGender on tblstudent(Name asc,Gender desc)
select * from tblstudent

What  is  Non-Clustered Index in Sql Server  A non clustered index is anologouse to an index in a textbox .The index will have pointers to store loction of data
Since the non clustered index is stored  separetly from actual data a table can have more than one non clustered index just now a book can have any index by chapters at the beginning and another index by common terms at the end
For Example
create nonclustered index Ix_tblStudent_Course on tblstudent(Course)

Note: In the index itself ,the data is stored in an asending or descending order of the index key ,which doesnot in any way influence the store of datain the table

create nonclustered index Ix_tblStudent_Course on tblstudent(Course desc)

Result


Difference  between Clustered and Non-Clustered Index in Sql Server

Only One clustered Index per table,where as you can have more than one non clustered index

Clustered Index is faster than non clustered index,because ,the clusered index has to refer back to table if selected column is  not present

Culstered Index determine the store order row in the table,and hence does not requeired additional disk space but where as a non Clustered index is stored separately from the table,additional storage space is requried
·