|
Dictionary
|
Hash Table
|
|
1-Dictionary
is a generic type
|
1-
Hash table isn’t a generic type
|
|
2-It
is a strongly type.
|
2:-
It is a weakly type
|
|
3-Need
no boxing and unboxing
|
3-Need
boxing and unboxing
|
|
4-
It is type safe
|
4-
No type safe
|
|
5-Not
thread safe
|
5-Thread safe
|
|
6-Define
in the namespace System.Collection.Generic
|
6-It
define in the namespace System.Collections
|
Tuesday, 7 April 2015
Dictionary vs Hash table
Sunday, 5 April 2015
how to create insert delete update and select using stored procedure in asp.net
Hi guys,
This blog we will discuss how to create insert, update,delete and select stored procedure and implement it in asp.net.
Stored
procedure for Insert:
create procedure spinsert(@UserId nvarchar(50),@UserName nvarchar(50)=null)
as
begin
insert into proc1 values(@UserId,@UserName)
end
Stored
prodecure for delete:
create proc spdelete(@UserId nvarchar(50)=null)
as
begin
delete from proc1 where UserId=@UserId
end
Stored procedure for Update:
create proc spupdate(@UserId nvarchar(50)=null,@UserName nvarchar(50)=null)
as
begin
update proc1 set UserId=@UserId,UserName=@UserName where UserId=@UserId
end
Stored procedure for select:
create proc spselect(@UserId nvarchar(50)=null,@UserName nvarchar(50)=null)
as
begin
select UserName from proc1 where UserId=@UserId
end
Now
we will discuss how to write code in code behind page for
insert , update , delete and update.
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 stp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection con = new SqlConnection(“uid=sa;password=123;database=naseer”);
private void insert_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand(“spinsert”,con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(“@UserId”,textBox1.Text);
cmd.Parameters.AddWithValue(“@UserName”,textBox2.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
//MessageBox.Show(“inserted
succesfully”);
Lblmsg.Text =”Insert Successfully”;
}
private void delete_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand(“spdelete”, con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(“@UserId”, textBox1.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
//MessageBox.Show(“deleted
succesfully”);
lblMsg.Text =”Delete data
Succesfully”;
}
private void update_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand(“spupdate”, con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(“@UserId”, textBox1.Text);
cmd.Parameters.AddWithValue(“@UserName”, textBox2.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
// MessageBox.Show(“updated
succesfully”);
LblMsg.Text =”Updated data successfully”;
}
private void select_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand(“spselect”, con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(“@UserId”, textBox1.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
if (dt.Rows.Count >
0)
{
textBox2.Text = dt.Rows[0][“UserName”].ToString();
}
else
{
// MessageBox.Show(“Please enter Correct UserID”);
lblMsg.Text =”plz
enter correct userid”;
}
}
}
}
Saturday, 4 April 2015
Types of classes in c sharp:-
Types of classes in c sharp:-
Hi guys,
This blog we will explain types of classes in
c #
Basically 4
types of classes available in c sharp. These are:
1:- Partial
class
2:- Static
class
3:- Abstract
class
4:-Sealed
class
Now we
discuss about all class and its functionality with in c sharp.
Partial class:-
Partial class introduced with .Net framework 2.0. It automatically generated within code behind
page. It is a special type of class allows its members like method, properties
and event to be divided into multiple source file (.cs). At compile time these
files get combined into a single class. It denoted by the keyword partial.
Adv: - It gives scope to developer simultaneously write
code.
Static class:-
1-Static class is a class we can’t be instantiated it.
2-It contains only static members.
3- It is sealed so we can’t be inherited.
4- It contains only static constractor.
Abstract class:-
1-Abstact class is a class we can’t instantiated it.
2-
An abstract class can implement methods.
3-- An abstract class can contain
constructors or destructors.
4-
It contain variables and concrete methods.
5- An abstract class cannot support multiple
inheritances.
6- It contain
access modifiers.
7-
An abstract class can contain fields.
Sealed class:-
A sealed class is a
class which cannot be inherited. A sealed class cannot be a base class.
Sometimes we may like to prevent a class being further sub classed for security
reasons. A class that can’t sub classed is called a sealed class.
Sealed class Aclass
{
}
Thursday, 2 April 2015
What are named and optional parameters in c# 4.0?
Hi guys
This article we will explain what is the new
c# features named and optional parameters
Named and
optional parameters available in c # 4.0 version. Now we discuss what is named.
Named:-
Named parameter
a developer can skip parameters that have default values and named only the
parameters that have non-default values.
Optional parameters:-
It gives
scope us to declare a default value to method parameter. So we don’t need to
define it every time when we call the method.
Example:-
Public class
A
{
Public static
void callme(string name= “Sanjib”,
string city =”New Delhi”, int id)
{}
Static void
main(string[] args)
{
Method(100);
// result of return method is(“Sanjib” ,”New Delhi”,100)
Subscribe to:
Posts (Atom)