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());
}

No comments:

Post a Comment

Comments Welcome

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...