开发者

retrieving row based on input

开发者 https://www.devze.com 2022-12-25 19:42 出处:网络
public void RemoveTask(int index) { SQL = \"DELETE FROM Task where (...) = \" +index; dbConn.Open(); dbCommand = new SqlCeCommand(SQL, dbConn);
public void RemoveTask(int index) {
  SQL = "DELETE FROM Task where (...) = " +index;

  dbConn.Open();

  dbCommand = new SqlCeCommand(SQL, dbConn);
  dbCommand.ExecuteNonQuery();

  dbConn.Close();
}

What i w开发者_JS百科ant to do is to delete the record based on the index which specified the row number but I don't know what function or variable should be used ( note the blank ), i try something like rowNum but it does not work.

any help will be appreaciated


It isn't entirely clear what you are trying to do. I think the following code is what you are after - it deletes a row based on the primary key where in this case the name of the primary key column is TaskId (but you can change that based on your table column names).

Note that it also uses parameterised SQL which gives better performance and security.

SQL = "DELETE FROM Task where TaskId = @taskid"; 

dbConn.Open(); 

dbCommand = new SqlCeCommand(SQL, dbConn); 

dbCommand.Parameters.Add("@taskid", SqlDbType.Int);
dbCommand.Parameters["@taskid"].Value = index;

dbCommand.ExecuteNonQuery(); 

dbConn.Close(); 
0

精彩评论

暂无评论...
验证码 换一张
取 消