Why on earth are you creating a SqlDataAdapter
and assigning it's SelectCommand
to delete something?!?!? Makes no sense at all....
Try something much easier:
public void deleteRecordByName(string Name)
{
string strcon = ConfigurationManager.ConnectionStrings["Dbconnection"].ConnectionString;
// create a SqlConnection and a SqlCommand to delete the data in a using().... block
using (SqlConnection sqlConnection = new SqlConnection(strcon))
using (SqlCommand cmd = new SqlCommand("dbo.hrm_DeleteLanguages2", sqlConnection))
{
// define this to be a stored procedure
cmd.CommandType = CommandType.StoredProcedure;
// define the parameter and set its value
cmd.Parameters.Add(new SqlParameter("@Name", SqlDbType.VarChar)).Value= Name;
// open connection, execute DELETE query, close connection
sqlConnection.Open();
cmd.ExecuteNonQuery();
sqlConnection.Dispose();
}
}
If you insist on using a SqlDataAdapter
, then please at least use the appropriate DeleteCommand
to delete rows - don't abuse the SelectCommand
for deleting data!