10 June 2010

What is difference between ExecuteReader, ExecuteNonQuery and ExecuteScalar.

What is difference between ExecuteReader, ExecuteNonQuery and ExecuteScalar ?

ExecuteReader : Use for accessing data. It provides a forward-only,read-only,connected recordset.

ExecuteNonQuery : Use for data manipulation, such as Insert, Update, Delete.

ExecuteScalar : Use for retrieving 1 row 1 col. value., i.e. Single value. eg: for retrieving aggregate function. It is faster than other ways of retrieving a single value from Database.

2 June 2010

view state in asp.net royalarun.blogspot.com

View State in Asp.net - royalarun.blogspot.com

Microsoft® ASP.NET view state is the technique used by an ASP.NET Web page to persist changes to the state of a Web Form across postbacks.

Difference Between VB.Net and C#.Net - royalarun.blogspot.com

Difference Between VB.Net and C#.Net

major differences between them :-

Advantages VB.NET :-

a).Has support for optional parameters which makes COM interoperability much easy.
b).With Option Strict off late binding is supported.Legacy VB functionalities can be used by using Microsoft.VisualBasic namespace.
c).Has the WITH construct which is not in C#.
d).The VB.NET part of Visual Studio .NET compiles your code in the background.
While this is considered an advantage for small projects, people creating very large projects have found that the IDE slows down considerably as the project gets larger.

Advantages of C#
a).XML documentation is generated from source code but this is now been incorporated in Whidbey.
b).Operator overloading which is not in current VB.NET but is been introduced in
Whidbey.
c).Use of this statement makes unmanaged resource disposal simple.
d).Access to Unsafe code. This allows pointer arithmetic etc, and can improve
performance in some situations. However, it is not to be used lightly, as a lot of the normal safety of C# is lost (as the name implies).This is the major difference that you can access unmanaged code in C# and not in VB.NET.

It is easier for Visual Basic 6.0 developers to use Visual Basic .NET and for C++/Java programmers to use Visual C# .NET. The existing experience of a programmer far outweighs the small differences between the two languages.

17 May 2010

Stored Procedure with parameter in C# with Sql Server for Insertion

Stored Procedure with parameter in C# with Sql Server for Insertion

Consider Table name:sampletable

field

username nvarchar(50)
mark1 int


Write it in Stored Procedure [if you create table first time, Then it automatically changed to alter]Procedure name-InsertUser


ALTER PROCEDURE [dbo].[InsertUser]
(
@username varchar(50),
@mark1 int
)
AS
INSERT INTO sampletable VALUES(@username, @mark1)


Coding in C#

protected void Button1_Click(object sender, EventArgs e)
{
string username=(TextBox1.Text);
string mark=(TextBox2.Text);
SqlConnection myConnection = new SqlConnection("user id=userid;" + "password=pwd;" + "Data source=localhost;" + "Integrated security=true;" + "database=sample;");
SqlCommand myCommand = new SqlCommand("InsertUser", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@username", SqlDbType.VarChar).Value = username;
myCommand.Parameters.Add("@mark1", SqlDbType.Int).Value = mark;
myConnection.Open();
int rows = myCommand.ExecuteNonQuery();
myConnection.Close();
}

Grid view in asp.net, C# using sql server

Grid view in asp.net, C# using sql server
protected void Button3_Click(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection("user id=userid;" + "password=pwd;" + "Data source=localhost;" + "Integrated security=true;" + "database=connectivitydb;");
try
{
myConnection.Open();
}
catch (Exception f)
{
Console.WriteLine(f.ToString());
}
try
{
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da = new SqlDataAdapter("select * from agedetail", myConnection);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
catch (Exception f)
{
Console.WriteLine(f.ToString());
}
}

royalarun.blogspot.com by ArunPrakash

15 May 2010

Asp.net, C# Connectivity with Sql server



using System.Data.SqlClient;
protected void Button1_Click(object sender, EventArgs e)

{

SqlConnection myConnection = new SqlConnection("user id=userid;" + "password=pwd;" + "Data source=localhost;" + "Integrated security=true;" + "database=connectivitydb;");
try
{
myConnection.Open();
}
catch (Exception f)
{
Console.WriteLine(f.ToString());
}
SqlCommand myCommand = new SqlCommand("Command String", myConnection);
myCommand.CommandText = ("INSERT into agedetail(name,age)" + values('ramasamy',24)");
myCommand.ExecuteNonQuery();
try{
myConnection.Close();
}
catch (Exception f)
{
Console.WriteLine(f.ToString());
}

Asp.net, C# Connectivity with Sql server



using System.Data.SqlClient;
protected void Button1_Click(object sender, EventArgs e)

{

SqlConnection myConnection = new SqlConnection("user id=userid;" + "password=pwd;" + "Data source=localhost;" + "Integrated security=true;" + "database=connectivitydb;");
try
{
myConnection.Open();
}
catch (Exception f)
{
Console.WriteLine(f.ToString());
}
SqlCommand myCommand = new SqlCommand("Command String", myConnection);

//myCommand.Connection = myConnection;
myCommand.CommandText = ("INSERT into agedetail(name,age)" + "values('ramasamy',24)");
myCommand.ExecuteNonQuery();
try
{
myConnection.Close();
}
catch (Exception f)
{
Console.WriteLine(f.ToString());
}
}

Implementing OAuth validation in a Web API

 I mplementing OAuth validation in a Web API Implementing OAuth validation in a Web API using C# typically involves several key steps to sec...