SQLCommand Practice
These are just to understand how to use sqlcommand functions like ExecuteNonQuery(),ExecuteScaler(); etc etc
The C# Part
string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
SqlConnection mySqlConnection = new SqlConnection(connStr);
mySqlConnection.Open();
SqlCommand mySqlCommand = new SqlCommand("update Person set City = 'LHR'", mySqlConnection);
//Use this if you want to use a store procedure
//mySqlCommand.CommandType = CommandType.StoredProcedure;
int result = mySqlCommand.ExecuteNonQuery();
The Web.Config Part (windows authentication)
<connectionStrings>
<add name="myConnectionString" connectionString="server=CHILLAX-339\SQLEXPRESS;database=TestingDB;Integrated Security=SSPI;"/>
</connectionStrings>
The C# Part
string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
SqlConnection mySqlConnection = new SqlConnection(connStr);
mySqlConnection.Open();
SqlCommand mySqlCommand = new SqlCommand("update Person set City = 'LHR'", mySqlConnection);
//Use this if you want to use a store procedure
//mySqlCommand.CommandType = CommandType.StoredProcedure;
int result = mySqlCommand.ExecuteNonQuery();
The Web.Config Part (windows authentication)
<connectionStrings>
<add name="myConnectionString" connectionString="server=CHILLAX-339\SQLEXPRESS;database=TestingDB;Integrated Security=SSPI;"/>
</connectionStrings>
Comments
Post a Comment