using(SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["connSpionshopString"].ConnectionString)) {connection.Open();string sql = "INSERT INTO klant(klant_id,naam,voornaam) VALUES(@param1,@param2,@param3)";SqlCommand cmd = new SqlCommand(sql,connection);cmd.Parameters.Add("@param1", SqlDbType.Int).value = klantId cmd.Parameters.Add("@param2", SqlDbType.Varchar, 50).value = klantNaam;cmd.Parameters.Add("@param3", SqlDbType.Varchar, 50).value = klantVoornaam;cmd.CommandType = CommandType.Text;cmd.ExecuteNonQuery(); }
syntax to create SqlCommand object SqlCommand = new SqlCommand("Command to execute i.e. (select,insert,update,delete))", connection objectname);ex: if u want to retrieve data from sql server we use select command i.e SqlComand cmd = new SqlCommnd("Select * from Table_Employee",conn);conn--> SqlConnection Object cmd--> SqlCommand Object
Sqlcommand com=new Sqlcommand(query,connection object);
Using(Sqlcommand cmd = new Sqlcommand(Select * from TableName,Sqlconnection)) {//Your code here }
sqlcommand cmd=new sqlcommand("select * from emp",con);con- connection object.
SqlConnection con = new SqlConnection("Data Source=ABC;Initial Catalog=studentdetail;uid=sa; pwd=Password1");SqlCommand cmd = new SqlCommand("Select * from Tablename",connection); con.open();